5 changed files with 85 additions and 0 deletions
@ -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; |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
package com.rental.shape; |
|||
|
|||
public abstract class Shape { |
|||
public abstract void draw(); |
|||
} |
|||
@ -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("----------------------------"); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
package com.rental.usb; |
|||
|
|||
public interface USB { |
|||
void open(); |
|||
void close(); |
|||
} |
|||
Loading…
Reference in new issue