5 changed files with 122 additions and 6 deletions
@ -0,0 +1,35 @@ |
|||||
|
public class Circle extends Shape{ |
||||
|
private double radius; |
||||
|
|
||||
|
public Circle() { |
||||
|
super(); |
||||
|
this.radius = 1.0; |
||||
|
} |
||||
|
|
||||
|
public Circle(double radius) { |
||||
|
super(); |
||||
|
this.radius = radius; |
||||
|
} |
||||
|
|
||||
|
public Circle(double radius,boolean isFilled,String color){ |
||||
|
super(isFilled, color); |
||||
|
this.radius = radius; |
||||
|
} |
||||
|
|
||||
|
public void setRadius(double radius){ |
||||
|
this.radius = radius; |
||||
|
} |
||||
|
|
||||
|
public double getRadius() { |
||||
|
return this.radius; |
||||
|
} |
||||
|
|
||||
|
public String toString() { |
||||
|
String ret = ""; |
||||
|
ret += "Radius: " + this.radius + "\n"; |
||||
|
double area = Math.PI * Math.pow(this.radius,2); |
||||
|
ret += "Area: " + area + "\n"; |
||||
|
ret += super.toString(); |
||||
|
return ret; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
public class Rectangle extends Shape{ |
||||
|
private double width; |
||||
|
private double length; |
||||
|
|
||||
|
public Rectangle() { |
||||
|
super(); |
||||
|
this.width = 1.0; |
||||
|
this.length = 2.0; |
||||
|
} |
||||
|
|
||||
|
public Rectangle(double width, double length){ |
||||
|
super(); |
||||
|
setLW(width,length); |
||||
|
} |
||||
|
|
||||
|
public Rectangle(double width, double length,boolean isFilled,String color) { |
||||
|
super(isFilled, color); |
||||
|
setLW(width,length); |
||||
|
} |
||||
|
|
||||
|
public double getWidth() { |
||||
|
return this.width; |
||||
|
} |
||||
|
|
||||
|
public double getLength() { |
||||
|
return this.length; |
||||
|
} |
||||
|
|
||||
|
public void setLW(double x, double y){ |
||||
|
this.length = Math.max(x,y); |
||||
|
this.width = Math.min(x,y); |
||||
|
} |
||||
|
|
||||
|
public double getArea() { |
||||
|
return this.length * this.width; |
||||
|
} |
||||
|
|
||||
|
public String toString() { |
||||
|
String ret = ""; |
||||
|
ret += "Width: " + this.width + "\n"; |
||||
|
ret += "Length: " + this.length + "\n"; |
||||
|
ret += "Area: " + getArea() + "\n"; |
||||
|
ret += super.toString(); |
||||
|
return ret; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
public class Shape{ |
||||
|
private boolean isFilled; |
||||
|
private String color; |
||||
|
|
||||
|
public Shape() { |
||||
|
this.isFilled = true; |
||||
|
this.color = "Green"; |
||||
|
} |
||||
|
|
||||
|
public Shape(boolean isFilled,String color){ |
||||
|
this.isFilled = isFilled; |
||||
|
this.color = color; |
||||
|
} |
||||
|
|
||||
|
public void setColor(String color) { |
||||
|
this.color = color; |
||||
|
} |
||||
|
|
||||
|
public void setIsFilled(boolean isFilled){ |
||||
|
this.isFilled = isFilled; |
||||
|
} |
||||
|
|
||||
|
public String getColor() { |
||||
|
return this.color; |
||||
|
} |
||||
|
|
||||
|
public boolean getIsFilled(){ |
||||
|
return this.isFilled; |
||||
|
} |
||||
|
|
||||
|
public String toString() { |
||||
|
String ret = ""; |
||||
|
ret += "Filled: "+this.isFilled + "\n"; |
||||
|
ret += "Color: "+this.color + "\n"; |
||||
|
return ret; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue