题目要求:矩形类
package 矩形类;
public class Test
{
public static void main(String[] args)
{
Rectangle a = new Rectangle(4, 40);
Rectangle b = new Rectangle(3.5, 35.9);
System.out.println("第一个矩形的 宽为:" + a.width + "高为:" + a.height + "面积为:"
+ a.getArea() + "周长为:" + a.getPerimeter());
System.out.println("第二个矩形的 宽为:" + b.width + "高为:" + b.height + "面积为:"
+ b.getArea() + "周长为:" + b.getPerimeter());
}
}
class Rectangle
{
double width;
double height;
Rectangle()
{
}
Rectangle(double newWidth, double newHeight)
{
width = newWidth;
height = newHeight;
}
double getArea()
{
return width * height;
}
double getPerimeter()
{
return 2 * (width + height);
}
}