java编程实践题_类和对象课内实践课 java练习题 按要求编写程序,完成以下功能?...

展开全部

package com.ZL;

public abstract class Shape {

public abstract double getArea(Shape extends T> a);

}

package com.ZL;

public class Circle extends Shape{

private double radius;

public Circle(double radius) {

e69da5e6ba9062616964757a686964616f31333431373839super();

this.radius = radius;

}

@Override

public double getArea(Shape a) {

Circle c = (Circle)a;

double r = c.radius;

return (Math.PI)*(Math.pow(r, 2));

}

}

package com.ZL;

public class Rectangle extends Shape{

private double length;

private double width;

public Rectangle(double length, double width) {

super();

this.length = length;

this.width = width;

}

@Override

public double getArea(Shape a) {

Rectangle r = (Rectangle)a;

return r.length * r.width;

}

}

package com.ZL;

public class Triangle extends Shape{

private double length;

private double heigth;

public Triangle(double length, double heigth) {

super();

this.length = length;

this.heigth = heigth;

}

@Override

public double getArea(Shape a) {

Triangle t = (Triangle)a;

return (t.length * t.heigth) / 2;

}

}

package com.ZL;

public class Trapezoid extends Shape{

private double upperLength;

private double bottonLength;

private double heigth;

public Trapezoid(double upperLength, double bottonLength, double heigth) {

super();

this.upperLength = upperLength;

this.bottonLength = bottonLength;

this.heigth = heigth;

}

@Override

public double getArea(Shape a) {

Trapezoid t = (Trapezoid)a;

return (t.upperLength + t.bottonLength) / 2 * t.heigth;

}

}

package com.ZL;

public class TestShape {

public static void main(String[] args) {

Shape circle = new Circle(5.3);

Shape rectangle = new Rectangle(3.0,6.6);

Shape triangle = new Triangle(8.0,5.0);

Shape trapezoid = new Trapezoid(4.0,7.2,12.0);

System.out.println(circle.getArea(circle));

System.out.println(rectangle.getArea(rectangle));

System.out.println(triangle.getArea(triangle));

System.out.println(trapezoid.getArea(trapezoid));

}

}

输出结果

88.24733763933729

19.799999999999997

20.0

67.19999999999999

这要是不采纳就说不过去了哈🧐

更多追问追答

追答

b56ab25d32d0e63d189d6afdccf36e58.png

2bcbccb994841eccc469f60a88f8d570.png

56d0f255bfddd96bdd89fc29d60dcb1a.png

cdbdd9684058f0de3fe7c6a0e03bacdc.png

5b48895cc030d469b0eaf92ade01df5d.png

8eb613bc46971de25e57cd5d5bea777c.png

4db65c2986d0bb9288b64bbc14ffcb0b.png

3a4f0ff324d5afdb240c01f6b1186105.png

915cb12dbc0356d2e4e6cbda6a64d63a.png

c56826fed5beb095f672dbf3011f1f56.png

a2f415783c07f8df62682e7deb38d094.png

6f3ccaec6c1b69d7e562de6183b4fa4b.png

7a92a6ca91f54a17639e16f22b3d8dba.png

8f810d70c4f3ec0f1b57883df400043e.png

尖括号里的代码被吞了,直接看图吧

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值