本文主要是介绍几何图形计算器的设计与实现----代码实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
点此处查看 课程设计说明书
1.创建实体类:
// Circle.java
public class Circle {private double r;public double getR() {return r;}public void setR(double r) {this.r = r;}@Overridepublic String toString() {return "Circle [r=" + r + "]";}public Circle() {super();}public Circle(double r) {super();this.r = r;}public double Circle_Space(){double space=3.14*r*r; return Math.round(space*100)/100.00;}public double Circle_Girth(){double girth=2*3.14*r;return Math.round(girth*100)/100.00;}
}
// Column.java public class Column {private double r;private double h;public double getR() {return r;}public void setR(double r) {this.r = r;}public double getH() {return h;}public void setH(double h) {this.h = h;}@Overridepublic String toString() {return "Column [r=" + r + ", h=" + h + "]";}public Column() {super();}public Column(double r, double h) {super();this.r = r;this.h = h;}public double Column_bottom_Space(){double space=3.14*r*r;return Math.round(space*100)/100.00;}public double Column_Surface_Space(){double space= 6.28*r*r+2*r*3.14*h;return Math.round(space*100)/100.00;}public double Column_Volume(){double volume= 3.14*r*r*h;return Math.round(volume*100)/100.00;}}
// Rectangle.javapublic class Rectangle {
private double height;
private double width;
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
@Override
public String toString() {
return "Rectangle [height=" + height + ", width=" + width + "]";
}
public Rectangle() {
super();
}
public Rectangle(double height, double width) {
super();
this.height = height;
this.width = width;
}
public double Rectangle_Girth(){
double girth=2*(height+width);
return Math.round(girth*100)/100.00;
}
public double Rectangle_Space(){
double space= height*width;
return Math.round(space*100)/100.00;
}
}
// Triangle.java public class Triangle {
private double a;
private double b;
private double c;
public double getA() {
return a;
} public void setA(double a) {
this.a = a;
} public double getB() {
return b;
} public void setB(double b) {
this.b = b;
} public double getC() {
return c;
} public void setC(double c) {
this.c = c;
} @Override
public String toString() {
return "Triangle [a=" + a + ", b=" + b + ", c=" + c + "]";
}
public Triangle() {
super();
}
public Triangle(double a, double b, double c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
public boolean isTriangle(){
if (a+b>c&&a+c>b&&b+c>a)
return true;
else
return false;
}
public double Triangle_Girth(){
return Math.round((a+b+c)*100)/100.00;
}
public double Triangle_Space(){
//System.out.println(a*b*c);
double p = (a+b+c) / 2;
double space=Math.pow(p*(p-a)*(p-b)*(p-c), 0.5);
return Math.round((space)*100)/100.00;
}}
2.创建视图
// Main.javaimport java.awt.*;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.e
这篇关于几何图形计算器的设计与实现----代码实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!