From 665bf54d818f3de565762c31bebdebcfc0bd71ed Mon Sep 17 00:00:00 2001 From: Lves <16744448+tong-zhehui@user.noreply.gitee.com> Date: Tue, 10 Mar 2026 10:49:04 +0000 Subject: [PATCH] update src/main/java/cn/zust/edu/cn/Rectangle.java. Signed-off-by: Lves <16744448+tong-zhehui@user.noreply.gitee.com> --- src/main/java/cn/zust/edu/cn/Rectangle.java | 79 +++++++++++++++++++-- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/src/main/java/cn/zust/edu/cn/Rectangle.java b/src/main/java/cn/zust/edu/cn/Rectangle.java index f70897e..b2ff408 100644 --- a/src/main/java/cn/zust/edu/cn/Rectangle.java +++ b/src/main/java/cn/zust/edu/cn/Rectangle.java @@ -1,8 +1,73 @@ package cn.zust.edu.cn; -/** - * - * @author czg - * @since 2023/3/7 10:50 - */ -public class Rectangle { -} + +public class Rectangle implements IShape { + private Point ptTopLeft; + private Point ptTopRight; + private int width; + private int height; + + public Rectangle() { + this.ptTopLeft = new Point(); + this.ptTopRight = new Point(); + this.width = 0; + this.height = 0; + } + + public Rectangle(Point topleft, int height, int width) { + this.ptTopLeft = new Point(topleft); + this.width = width; + this.height = height; + this.ptTopRight = new Point(topleft.getX() + width, topleft.getY()); + } + + @Override + public double perimeter() { + return 2 * (width + height); + } + + @Override + public double area() { + return width * height; + } + + @Override + public void draw() { + System.out.println("绘制矩形:"); + System.out.println(" 左上角点: " + ptTopLeft); + System.out.println(" 右上角点: " + ptTopRight); + System.out.println(" 宽度: " + width + ", 高度: " + height); + System.out.println(" 周长: " + perimeter() + ", 面积: " + area()); + } + + public Point getPtTopLeft() { + return ptTopLeft; + } + + public void setPtTopLeft(Point ptTopLeft) { + this.ptTopLeft = ptTopLeft; + } + + public Point getPtTopRight() { + return ptTopRight; + } + + public void setPtTopRight(Point ptTopRight) { + this.ptTopRight = ptTopRight; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } +} \ No newline at end of file -- Gitee