diff --git a/Circle.java b/Circle.java index e69de29..4fcd458 100644 --- a/Circle.java +++ b/Circle.java @@ -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; + } +} \ No newline at end of file diff --git a/Rectangle.java b/Rectangle.java new file mode 100644 index 0000000..0a16f7b --- /dev/null +++ b/Rectangle.java @@ -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; + } +} \ No newline at end of file diff --git a/Shape.java b/Shape.java index e69de29..a96d040 100644 --- a/Shape.java +++ b/Shape.java @@ -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; + } +} \ No newline at end of file diff --git a/TestParseString.java b/TestParseString.java index ea4f712..9641ff7 100644 --- a/TestParseString.java +++ b/TestParseString.java @@ -7,7 +7,7 @@ public class TestParseString System.out.println("Sum of all number in \"" + s1 + "\" is: "); System.out.println(ps1.sumOfAll()); System.out.println(); - + String s2 = "120,8 7.3,6.4 0.1,8.0"; ParseString ps2 = new ParseString(s2); System.out.println("Sum of all number in \"" + s2 + "\" is: "); diff --git a/TestShape.java b/TestShape.java index 8783b9e..dc6b454 100644 --- a/TestShape.java +++ b/TestShape.java @@ -2,26 +2,24 @@ public class TestShape { public static void main(String[] args) { - /* Circle c1 = new Circle(2.67); System.out.println("c1: "); System.out.println(c1.toString()); System.out.println(); - + Circle c2 = new Circle(3, false, "Red"); System.out.println("c2: "); System.out.println(c2.toString()); System.out.println(); - + Rectangle r1 = new Rectangle(3, 2, true, "Blue"); System.out.println("r1: "); System.out.println(r1.toString()); System.out.println(); - + Rectangle r2 = new Rectangle(3.2, 4, false, "Red"); System.out.println("r2: "); System.out.println(r2.toString()); - */ } }