编写一个java应用程序,该程序中有3个类:Lader、Circle和主类Test。具体要求如下:Lader类具有类型为doubl
编写一个java应用程序,该程序中有3个类:Lader、Circle和主类Test。具体要求如下:Lader类具有类型为double的上底、下底、高、面积,具有返回面积的...
编写一个java应用程序,该程序中有3个类:Lader、Circle和主类Test。具体要求如下:Lader类具有类型为double的上底、下底、高、面积,具有返回面积的功能,包括一个构造方法对上底、下底、高进行初始化。Circle类具有类型为double的半径、周长和面积属性,具有返回长、面积的功能,包括一个构造方法对半径进行初始化。主要类Test用来测试类Lader和类Circle的功能。
展开
2个回答
展开全部
//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();
}
}
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();
}
}
展开全部
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;
}
}
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;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询