public class Rectangle {
private int widthT = 0
private int heightT = 0
Point point = new Point()
public Rectangle(int width, int height, int centerX, int centerY) {
widthT = width
heightT = height
point.x = centerX
point.y = centerY
}
public int width() {
return widthT
}
public int height() {
return heightT
}
public int centerX() {
return point.x
}
public int centerY() {
return point.y
}
}
麻烦采纳呦~~~亲
// 矩形public class RectangleDemo {
public static void main(String[] args) {
RectangleDemo demo = new RectangleDemo(12, 32)
System.out.println(demo.getPerimeter())
System.out.println(demo.getArea())
demo = new RectangleDemo()
System.out.println(demo.getArea())
System.out.println(demo.getPerimeter())
demo.setHeight(50)
demo.setWidth(30)
System.out.println(demo.getArea())
System.out.println(demo.getPerimeter())
}
// 求周
public double getPerimeter() {
return (height + width) * 2
}
// 求面积
public double getArea() {
return height * width
}
public RectangleDemo(double height, double width) {
this.height = height
this.width = width
}
public RectangleDemo() {
this.height = 10
this.width = 10
}
private double height// 高度
private double width// 宽度
public double getHeight() {
return height
}
public void setHeight(double height) {
this.height = height
}
public double getWidth() {
return width
}
public void setWidth(double width) {
this.width = width
}
}
编写矩形类RectangleJava程序矩形类两数据员别rLength宽rWidth通getLength()、getWidth()、getArea()别查看矩形、宽面积通setLength()setWidth()重新设置矩形宽