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