编写一个java应用程序,该程序中有3个类:Lader、Circle和主类Test。具体要求如下:Lader类具有类型为doubl

编写一个java应用程序,该程序中有3个类:Lader、Circle和主类Test。具体要求如下:Lader类具有类型为double的上底、下底、高、面积,具有返回面积的功能,包括一个构造方法对上底、下底、高进行初始化。Circle类具有类型为double的半径、周长和面积属性,具有返回长、面积的功能,包括一个构造方法对半径进行初始化。主要类Test用来测试类Lader和类Circle的功能。

//Lader类
public class Lader {
double sd;
double xd;
double height;
double area;

Lader(double sd,double xd,double height){
this.sd=sd;
this.xd=xd;
this.height=height;
}

public void area(){
area=1.0/2*(sd+xd)*height;
System.out.println("梯形面积是:"+area);
}
}

//Circle类
public class Circle {
double r;
double circle;
double s;

Circle(double r){
this.r=r;
}

public void area(){
circle=2*Math.PI*r;
s=Math.PI*Math.pow(r, 2);
System.out.println("圆的周长为:"+circle);
System.out.println("圆的面积是:"+s);
}
}

//测试类
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Circle circle=new Circle(5);
circle.area();

Lader lader =new Lader(2,3,4);
lader.area();
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-04
public class $ {

public static void main(String... _) {
Lader lader = new Lader(1.0, 100.0, 100.0);
System.out.println("lader的面积:" + lader.getArea());

Circle c = new Circle(100.0);
System.out.println("Circle的周长:" + c.getZhouchang());
System.out.println("Circle的面积:" + c.getArea());
}
}

class Lader {
private double shangdi;

private double xiadi;

private double gao;

public Lader(double shangdi, double xiadi, double gao) {
this.shangdi = shangdi;
this.xiadi = xiadi;
this.gao = gao;
}

public double getArea() {
return (shangdi + xiadi) * gao / 2.0;
}
}

class Circle {
private double r;

public Circle(double r) {
this.r = r;
}

public double getZhouchang() {
return 2 * Math.PI * r;
}

public double getArea() {
return Math.PI * r * r;
}
}

Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答