class Rectangle
{
private double width = 1.0;
private double height = 1.0;
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;
}
//计算周长的方法
public double getPerimeter()
{
return (width + height) * 2;
}
//计算面积的方法
public double getArea()
{
return width * height;
}
}
public class Test4{
public static void main(String[] args)
{
Rectangle rec = new Rectangle(3.6,5.8);
System.out.println("The perimeter is:" + rec.getPerimeter());
System.out.println("The area of is:" + rec.getArea());
System.out.println("The color is:" + rec.getColor());
}
}
{
private double width = 1.0;
private double height = 1.0;
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;
}
//计算周长的方法
public double getPerimeter()
{
return (width + height) * 2;
}
//计算面积的方法
public double getArea()
{
return width * height;
}
}
public class Test4{
public static void main(String[] args)
{
Rectangle rec = new Rectangle(3.6,5.8);
System.out.println("The perimeter is:" + rec.getPerimeter());
System.out.println("The area of is:" + rec.getArea());
System.out.println("The color is:" + rec.getColor());
}
}