From 3b0c8fd75e49a5bc97b0bfd9eb34201f3bdd18b9 Mon Sep 17 00:00:00 2001 From: JiangYouhan <3080587852@qq.com> Date: Mon, 6 Apr 2026 23:59:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w5/Circle.java | 22 ++++++++++++++++++++++ w5/Rectangle.java | 32 ++++++++++++++++++++++++++++++++ w5/Shape.java | 5 +++++ w5/ShapeTest.java | 20 ++++++++++++++++++++ w5/USB.java | 6 ++++++ 5 files changed, 85 insertions(+) create mode 100644 w5/Circle.java create mode 100644 w5/Rectangle.java create mode 100644 w5/Shape.java create mode 100644 w5/ShapeTest.java create mode 100644 w5/USB.java diff --git a/w5/Circle.java b/w5/Circle.java new file mode 100644 index 0000000..eeaf22d --- /dev/null +++ b/w5/Circle.java @@ -0,0 +1,22 @@ +package com.rental.shape; + +public class Circle extends Shape { + private double radius; + + public Circle(double radius) { + this.radius = radius; + } + + @Override + public void draw() { + System.out.println("绘制一个半径为" + radius + "的圆形"); + } + + public double getRadius() { + return radius; + } + + public void setRadius(double radius) { + this.radius = radius; + } +} \ No newline at end of file diff --git a/w5/Rectangle.java b/w5/Rectangle.java new file mode 100644 index 0000000..98a970e --- /dev/null +++ b/w5/Rectangle.java @@ -0,0 +1,32 @@ +package com.rental.shape; + +public class Rectangle extends Shape { + private double width; + private double height; + + public Rectangle(double width, double height) { + this.width = width; + this.height = height; + } + + @Override + public void draw() { + System.out.println("绘制一个宽为" + width + "、高为" + height + "的矩形"); + } + + 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; + } +} \ No newline at end of file diff --git a/w5/Shape.java b/w5/Shape.java new file mode 100644 index 0000000..fb1f580 --- /dev/null +++ b/w5/Shape.java @@ -0,0 +1,5 @@ +package com.rental.shape; + +public abstract class Shape { + public abstract void draw(); +} \ No newline at end of file diff --git a/w5/ShapeTest.java b/w5/ShapeTest.java new file mode 100644 index 0000000..ac89593 --- /dev/null +++ b/w5/ShapeTest.java @@ -0,0 +1,20 @@ +package com.rental.shape; + +public class ShapeTest { + public static void drawShape(Shape s) { + s.draw(); + } + + public static void main(String[] args) { + System.out.println("基础题测试:"); + System.out.println("----------------------------"); + + Shape circle = new Circle(5.0); + Shape rectangle = new Rectangle(4.0, 6.0); + + drawShape(circle); + drawShape(rectangle); + + System.out.println("----------------------------"); + } +} \ No newline at end of file diff --git a/w5/USB.java b/w5/USB.java new file mode 100644 index 0000000..f1ccf3e --- /dev/null +++ b/w5/USB.java @@ -0,0 +1,6 @@ +package com.rental.usb; + +public interface USB { + void open(); + void close(); +} \ No newline at end of file