长方形有两个点坐标,三角形中有三个点坐标,圆有圆心和半径,怎么用多态来写,类中的方法有周长和面积
------解决方案--------------------------------------------------------
public class Point{
private long x ;
private long y ;
public Point(long x ,long y){
this.x = x ;
this.y = y ;
}
}
public abstract class Graphics{
public long perimeter() ;
public long area() ;
}
public class Rectangle extends Graphics{
private Point bPoint ;
private Point ePoint ;
public Rectangle(){}
public Rectangle(Point bPoint, Point ePoint){
this.bPoint = bPoint ;
this.ePoint = ePoint ;
}
public long perimeter() {
//自己计算了
}
public long area() {
//自己计算了
}
}
其他类类似 Rectangle
main(String[] args){
Graphics g = new Rectangle(new Point(0, 1), new Point(5,5)) ;
System.out.println(g.area() + "----" + g.perimeter()) ;
}
------解决方案--------------------------------------------------------