标签:实验报告 图片 double inf rectangle new public return 实验
(1) 使用构造函数完成各属性的初始赋值
(2) 使用get…()和set…()的形式完成属性的访问及修改
(3) 提供计算面积的getArea()方法和计算周长的getLength()方法
class Rectangle {
private double width,height;
private String color;
public Rectangle(double width,double height,String color){
this.setWidth(width);
this.setHeight(height);
this.setColor(color);
}
public void tell(){
System.out.println("宽:"+width+" "+"高:"+height+" "+"颜色:"+color);
}
public double getWidth(){
return width;
}
public double getHeight(){
return height;
}
public String getColor(){
return color;
}
public void setWidth(double width){
this.width=width;
}
public void setHeight(double height){
this.height=height;
}
public void setColor(String color) {
this.color=color;
}
public void getArea(){
System.out.println("面积为:"+(width*height));
}
public void getLength(){
System.out.println("周长为:"+(width+height)*2);
}
}
public class Test{
public static void main(String[] args){
Rectangle per=new Rectangle(30,60,"yellow");
per.tell();
per.getArea();
per.getLength();
}
}
标签:实验报告 图片 double inf rectangle new public return 实验
原文地址:https://www.cnblogs.com/chenxiaolong-cxl/p/11551738.html