java题目,求助
在edu.abc.test1包,编写控制台程序,实现如下功能。该程序中有3个类:Ladder(梯形)、Circle(圆形)和测试类Test。Ladder类具有类型为dou...
在edu.abc.test1包,编写控制台程序,实现如下功能。该程序中有3个类:Ladder(梯形)、Circle(圆形)和测试类Test。Ladder类具有类型为double的上底、下底、高、面积属性,具有返回面积的功能,包括一个构造方法对上底、下底、高进行初始化。Circle类具有类型为double的半径、周长和面积属性,具有返回周长、面积的功能,包括一个构造方法对半径进行初始化。测试类Test用来测试类Ladder和类Circle的功能。给定上底、下底、高求面积,给定圆的半径求周长和面积程序结果如下:
展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
package edu.abc.test1;
public class Ladder {
private double top;
private double lower;
private double height;
private double area;
public Ladder(){
this.top = 0;
this.lower = 0;
this.height = 0;
}
public Ladder(double top,double lower,double height){
this.top = top;
this.lower = lower;
this.height = height;
}
public double getArea(){
return (top+lower)/2*height;
}
}
package edu.abc.test1;
public class Circle {
private double d;
private double circle;
private double area;
public Circle(){
this.d = 0;
}
public Circle(double d){
this.d = d;
}
public double getArea(){
return Math.PI*d*d;
}
public double getCircle(){
return Math.PI*d*2;
}
}
package edu.abc.test1;
public class Test {
public static void main(String[] args){
double top = 1;
double lower = 3;
double height = 5;
Ladder l = new Ladder(top, lower, height);
System.out.println("梯形面积为:" + l.getArea());
double d = 1;
Circle c = new Circle(d);
System.out.println("圆周长为:" + l.getArea());
System.out.println("圆面积为:" + l.getArea());
}
}
public class Ladder {
private double top;
private double lower;
private double height;
private double area;
public Ladder(){
this.top = 0;
this.lower = 0;
this.height = 0;
}
public Ladder(double top,double lower,double height){
this.top = top;
this.lower = lower;
this.height = height;
}
public double getArea(){
return (top+lower)/2*height;
}
}
package edu.abc.test1;
public class Circle {
private double d;
private double circle;
private double area;
public Circle(){
this.d = 0;
}
public Circle(double d){
this.d = d;
}
public double getArea(){
return Math.PI*d*d;
}
public double getCircle(){
return Math.PI*d*2;
}
}
package edu.abc.test1;
public class Test {
public static void main(String[] args){
double top = 1;
double lower = 3;
double height = 5;
Ladder l = new Ladder(top, lower, height);
System.out.println("梯形面积为:" + l.getArea());
double d = 1;
Circle c = new Circle(d);
System.out.println("圆周长为:" + l.getArea());
System.out.println("圆面积为:" + l.getArea());
}
}
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询