JAVA作业,求大神帮忙求帮忙求帮忙!在线等,出来秒采纳!悬赏或价格可商量!
4个回答
展开全部
这个题目因为没有设计到多态,且自身属性里面包含周长和面积其实有点不合理,以下是代码。
package weimo;
//梯形
public class Ladder {
private double topline; //上底
private double baseline; //下底
private double height; //高
private double area; //面积
//构造方法赋值
public Ladder(double topline, double baseline, double height) {
this.topline = topline;
this.baseline = baseline;
this.height = height;
}
public double getTopline() {
return topline;
}
public void setTopline(double topline) {
this.topline = topline;
}
public double getBaseline() {
return baseline;
}
public void setBaseline(double baseline) {
this.baseline = baseline;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getArea() {
return area;
}
public void setArea(double area) {
this.area = area;
}
//求梯形面积的方法
public double acquireArea(double topline, double baseline, double height){
area = (topline + baseline) * height / 2;
return area;
}
}
package weimo;
//圆形
public class Circle {
private double radius; //半径
private double perimeter; //周长
private double area; //面积
//构造方法对半径进行初始化
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getPerimeter() {
return perimeter;
}
public void setPerimeter(double perimeter) {
this.perimeter = perimeter;
}
public double getArea() {
return area;
}
public void setArea(double area) {
this.area = area;
}
//求圆周长
public double acquirePerimeter(double radius){
return 2 * 3.14 * radius;
}
//求圆面积
public double acquireArea(double radius){
return 3.14 * radius * radius;
}
}
package weimo;
//测试类
public class Test {
public static void main(String[] args) {
Ladder ladder = new Ladder(3, 4, 2);
System.out.println("梯形的面积为:" + ladder.acquireArea(ladder.getTopline(), ladder.getBaseline(), ladder.getHeight()));
Circle circle = new Circle(1);
System.out.println("圆的周长为:" + circle.acquirePerimeter(circle.getRadius()));
System.out.println("圆的面积为:" + circle.acquireArea(circle.getRadius()));
}
}
输出结果如下(特意设置长度和题目上显示的一样):
展开全部
不堪盈手赠,还寝梦佳期。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package com.wuliao;
public class tixing {
private double shangdi;
private double xidi;
private double gao;
public tixing(double shangdi, double xidi, double gao) {
super();
this.shangdi = shangdi;
this.xidi = xidi;
this.gao = gao;
}
public double tomianji() {
/*面积公式:(上底+下底)×高÷2*/
return (shangdi+xidi)*gao/2;
}
public double getShangdi() {
return shangdi;
}
public void setShangdi(double shangdi) {
this.shangdi = shangdi;
}
public double getXidi() {
return xidi;
}
public void setXidi(double xidi) {
this.xidi = xidi;
}
public double getGao() {
return gao;
}
public void setGao(double gao) {
this.gao = gao;
}
}
package com.wuliao;
public class yuanxing {
private double banjing;
private double pi=Math.PI; //π
public double tozhouchang() {
/*2πr*/
return 2*pi*banjing;
}
public double tomianji() {
/* πr²*/
return pi*banjing*banjing;
}
public yuanxing(double banjing) {
super();
this.banjing = banjing;
}
public double getBanjing() {
return banjing;
}
public void setBanjing(double banjing) {
this.banjing = banjing;
}
}
package com.wuliao;
public class test {
public static void main(String[] args) {
tixing tx = new tixing(1,2,3);
yuanxing yx = new yuanxing(3);
System.out.println("梯形的面积是:"+tx.tomianji());
System.out.println("圆的周长是:"+yx.tozhouchang());
System.out.println("梯形的面积是:"+tx.tomianji());
}
}
都是用拼音,换成你的就好了.-0 - 打发时间懒得查英文!!!! -0 -为啥不传参,自己百度吧,学习电东西吧,小盆友!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询