设计一个表示矩形的类Rect,其矩形数据成员有长 floatLength ,宽float Width,设计相应成员方法,实现下列功能:
1构造方法初始化长和宽。
②设计改变长和宽的成员方法,并设计获得长和宽的成员方法,
③计算并返回长方形的周长
④计算并返回长方形的面积。
⑤将该类封装为jar包。
参考代码如下:
package com.yelang.case4;
public class Rect {
private float length;
private float width;
public float getLength() {
return length;
}
public void setLength(float length) {
this.length = length;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
public Rect() {
super();
}
public Rect(float length, float width) {
super();
this.length = length;
this.width = width;
}
public float getArea() {
return this.length * this.width;
}
public float getRound() {
return (this.length + this.width) * 2;
}
public static void main(String[] args) {
Rect rect = new Rect(5.1F, 6F);
System.out.println(rect.getLength());
System.out.println(rect.getArea());
System.out.println(rect.getRound());
}
}