public class Triangle {
private double side1;
private double side2;
private double side3;
public Triangle() {
}
public Triangle(double s1, double s2, double s3) {
side1 = s1;
side2 = s2;
side3 = s3;
}
public double getSide1() {
return side1;
}
public double getSide2() {
return side2;
}
public double getSide3() {
return side3;
}
public void setSide1(double s1) {
side1 = s1;
}
public void setSide2(double s2) {
side2 = s2;
}
public void setSide3(double s3) {
side3 = s3;
}
public double getArea() {
double s = (side1 + side2 + side3) / 2;
return Mathsqrt(s (s - side1) (s - side2) (s - side3));
}
public double getPerimeter() {
return side1 + side2 + side3;
}
}
class Circle
{
double radius;
double diameter;
double area;
public Circle()
{
radius=1;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
thisradius = radius;
}
//下面这个方法用于计算机圆的直径
public double computeDiameter()
{
return 2radius;
}
public double computeArea()
{
return MathPIradiusradius;
}
}
public class TestCircle {
public static void main(String args[])
{
Circle c1=new Circle();
Circle c2=new Circle();
Circle c3=new Circle();
c2setRadius(5);
c3setRadius(10);
Systemoutprint("第一个圆的直径为:"+c1computeDiameter());
Systemoutprintln(" 面积为:"+c1computeArea());
Systemoutprint("第二个圆的直径为:"+c2computeDiameter());
Systemoutprintln(" 面积为:"+c2computeArea());
Systemoutprint("第三个圆的直径为:"+c3computeDiameter());
Systemoutprintln(" 面积为:"+c3computeArea());
}
}
public class Car1 extends Car {
public String manufacturer;
public Car1(String color, String style, String manufacturer) {
super(color, style);
thismanufacturer = manufacturer;
}
public Car1(String color) {
thiscolor = color;
thismanufacturer = "上海大众";
}
@Override
public String toString() {
return "Car1 [manufacturer=" + manufacturer + ", color=" + color + ", style=" + style + "]";
}
public Car1() {
super();
}
public static void main(String[] args) {
Car1 a = new Car1();
Car1 b = new Car1("黑色", "卡车", "斯泰尔");
Car1 c = new Car1("白色");
Systemoutprintln(atoString());
Systemoutprintln(btoString());
Systemoutprintln(ctoString());
}
}
class Car {
public String color;
public String style;
public Car() {
thiscolor = "red";
thisstyle = "car";
}
public Car(String color, String style) {
thiscolor = color;
thisstyle = style;
}
public void showColor() {
Systemoutprintln("颜色 " + thiscolor);
}
public void showStyle() {
Systemoutprintln("型号 " + thisstyle);
}
}
以上就是关于java程序设计课后习题 求解 看问题补充全部的内容,包括:java程序设计课后习题 求解 看问题补充、java 程序设计题目解答、java程序设计,求答案等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)