标签:ati turn length 变量 长度 double title 报告 hellip
实验二 Java简单类与对象
(1) 使用构造函数完成各属性的初始赋值
(2) 使用get…()和set…()的形式完成属性的访问及修改
(3) 提供计算面积的getArea()方法和计算周长的getLength()方法
1.1.实验源码:
class Rectangle {
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Rectangle(double width,double height,String color) {
this.setColor(color);
this.setHeight(height);
this.setWidth(width);
}
private double width;
private double height;
private String color;
public double getArea() {
return width * height;
}
public double getLength() {
return 2 * (width + height);
}
}
public class work{
public static void main(String args[]) {
Rectangle juxing;
juxing = new Rectangle(8,6,"black");
System.out.println("面积:"+juxing.getArea());
System.out.println("周长:"+juxing.getLength());
System.out.println("颜色:"+juxing.getColor());
}
}
1.2.实验结果

总结:这次的实验比上次难一点,所以第二个就没有写。第一个感觉还好,就是运用了this,get,set,三个知识点,这些老师都讲过,运行起来也没什么大错误,希望第二个题老师上课讲的时候能听懂吧。
本周学习了string类,对象数组,包等等,老师上课讲的还不错,不过上课开火箭是老师的常态,课后自学复习是很有必要的,不然听课的效率就很低。本周学习的内容应用到了生活上,能解决一些生活实际问题了,感觉还不错,继续加油!
标签:ati turn length 变量 长度 double title 报告 hellip
原文地址:https://www.cnblogs.com/lyp82ndl/p/11558823.html