public class Rectangle
{
private double width;
private double height;
private String color="white";
//无参构造器
public Rectangle()
{}
//有参构造器
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
//属性的get和set方法定义
public void setWidth(double width)
{
this.width = width;
}
public double getWidth()
{
return this.width;
}
public void setHeight(double height)
{
this.height = height;
}
public double getHeight()
{
return this.height;
}
public void setColor(String color)
{
this.color=color;
}
public String getColor()
{
return this.color;
}
//计算周长的方法
private double getPerimeter()
{
return (width+height)*2;
}
//计算面子的方法
private double getArea()
{
return width*height;
}
public static void main(String[] args)
{
Rectangle rec = new Rectangle(3.6,5.8);
System.out.println("The perimeter of Rectangle is:"+rec.getPerimeter());
System.out.println("The area of Rectangle is:"+rec.getArea());
System.out.println("The color of Rectangle is:"+rec.getColor());
}
}