/*
* Copyright (c) 2015,烟台大学计算机学院
* All right reserved.
* 文件名:flower.java
* 作者:柴银平
* 完成时间:2015年10月20日
* 版本号:v1.0
*
*
* 问题描述:设计一个长方形类,类里可以求出长方形的面积和周长,初始化两个,最后输出这两个的宽、高、面积周长
*
* 程序输入:
*
* 程序输出: 输出宽、高、面积、周长
*/
public class Rectangle {
public static void main(String[] args) {
Rectangle1 c=new Rectangle1(4,40);
Rectangle1 b=new Rectangle1(3.5,35.9);
System.out.println("The width and height of rectangle c is "+c.width+" and "+
c.height);
System.out.println("The area and perimeter of rectangle c is "+c.getArea()+" and "+
c.getPerimeter());
System.out.println("The width and height of rectangle b is "+b.width+" and "+
b.height);
System.out.println("The area and perimeter of rectangle b is "+b.getArea()+" and "+
b.getPerimeter());
}
}
class Rectangle1{
double width;
double height;
Rectangle1(){
width=1.0;
height=1.0;
}
Rectangle1(double x,double y){
width=x;
height=y;
}
double getArea()
{
return width*height;
}
double getPerimeter(){
return 2.0*(width+height);
}
}
测试图示: