下面是一个有关几何图形类的程序,请补充完整_;(1)public class Geometric {private String color;private boolean filled;private Date date;public Geometric(){date =new Date();}public Geometric(String color,boolean filled){this.color =color;this.filled =filled;_;(2)//获取系统时间}public void setColor(String color){this.color =color;}public String getColor(){return color;}public void setFilled(boolean filled){this.filled =filled;}_{(3)//获取是否填充的方法return filled;}public Date getDate(){return date;}public String toString(){return "颜色:"+color +",是否填充:"+filled +",创建时间:"+date ;}public double getArea(){return 0;}}//圆类继承图形类public class Circle _(4){private double radius;public Circle(){}public Circle(double radius,String color,boolean filled){_;(5)this.radius =radius;}public double getRadius(){return radius;}public void setRadius(double radius){this.radius =radius;}public double getArea(){return radius*radius*Math.PI;}public double getPerimeter(){return 2*radius*Math.PI;}public double getDiameter(){return 2*radius;}@_(6)//判断是否是方法的重写public String toString(){return "圆形:【半径为:"+radius +",颜色为:"+getColor()+",是否填充"+isFilled()+",创建时间:"+getDate();}}//长方形类继承图形类public class Rectangle _{(7)private double length;private double width;public Rectangle(){_;(8)//调用父类构造方法}public Rectangle(String color,boolean filled,double length,double width){super(color,filled);this.length =length;this.width =width;}public double getLength(){return length;}public void setLength(double length){this.length =length;}public double getWidth(){return width;}public void setWidth(double width){this.width =width;}public double getArea(){_;(9)}public double getPerimeter(){return 2*(length+width);}@Override public String toString(){return "长方形【长:"+length +"宽:"+width +super.toString()+"】";}}//测试类public class Test {public static void main(String[]args){Geometric g =_;//(10)利用上转型使父类对象指向圆类对象,使用无参构造g =_;//(11)利用上转型使父类对象指向长方形对象,使用无参构造Rectangle re;if (g _){//(12)判断g是否属于长方形类re =_;//(13)对象下转型}else {System.out.println("类型不匹配");}}}
发布时间:2024-04-03 10:25:14