public class Rectangle {
private static Rectangle rectangle;
private double width,height,r;
private String color,color1;
Rectangle(){width=0.0;height=0.0;}
Rectangle(double width,double height,String color){this.width=width;this.height=height;this.color=color;}
public double setwidth(){return width-0;}
public double setheight(){return height-0;}
public String setColor(String color){return color;}
public double getArea(){
return setwidth()*setheight();
}
public String toString()
{
return "矩形宽"+ setwidth()+"矩形长"+setheight()+"矩形面积"+getArea()+"矩形的颜色"+ setColor(color);
}
public String toS()
{
return "正方形边长"+ setwidth()+"正方形面积"+getArea()+"正方形的颜色"+ setColor(color);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println("初始化的矩形");
Rectangle.rectangle=new Rectangle();
System.out.println(rectangle.toString());
System.out.println("修改后的矩形");
Rectangle.rectangle=new Rectangle(10,20,null);
System.out.println(rectangle.toString());
System.out.println("修改颜色后的矩形");
Rectangle r = new Rectangle();
Rectangle.rectangle=new Rectangle(10,20,"红色");
System.out.println(rectangle.toString());
System.out.println("新建一个新矩形");
Rectangle.rectangle=new Rectangle(10,30,null);
System.out.println(rectangle.toString());
System.out.println("新建一个正方形");
Rectangle.rectangle=new Rectangle(1,1,null);
System.out.println(rectangle.toS());
}
}
开始发表,抄袭的是小狗。