Browse Source

上传文件至 'w5'

main
JiangYouhan 2 weeks ago
parent
commit
3b0c8fd75e
  1. 22
      w5/Circle.java
  2. 32
      w5/Rectangle.java
  3. 5
      w5/Shape.java
  4. 20
      w5/ShapeTest.java
  5. 6
      w5/USB.java

22
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;
}
}

32
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;
}
}

5
w5/Shape.java

@ -0,0 +1,5 @@
package com.rental.shape;
public abstract class Shape {
public abstract void draw();
}

20
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("----------------------------");
}
}

6
w5/USB.java

@ -0,0 +1,6 @@
package com.rental.usb;
public interface USB {
void open();
void close();
}
Loading…
Cancel
Save