diff --git a/Chapter7/Shape5.java b/Chapter7/Shape5.java new file mode 100644 index 0000000..f7548ef --- /dev/null +++ b/Chapter7/Shape5.java @@ -0,0 +1,23 @@ + +public class Shape5 { + + public static void main(String[] args) { + + Triangle5 t1 = new Triangle5("filled", 4.0, 4.0); + Triangle5 t2 = new Triangle5("Outlined", 8.0, 12.0); + + System.out.println("Info for t1: "); + t1.showStyle(); + t1.showDim(); + System.out.println("Area is " + t1.area()); + + System.out.println(); + + System.out.println("Info for t2: "); + t2.showStyle(); + t2.showDim(); + System.out.println("Area is " + t2.area()); + + } + +} diff --git a/Chapter7/Shape6.java b/Chapter7/Shape6.java new file mode 100644 index 0000000..95ac900 --- /dev/null +++ b/Chapter7/Shape6.java @@ -0,0 +1,16 @@ + +public class Shape6 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + Triangle6 t1 = new Triangle6(); + + System.out.println("Info for t1: "); + t1.showStyle(); + t1.showDim(); + System.out.println("Area is " + t1.area()); + + } + +} diff --git a/Chapter7/Triangle6.java b/Chapter7/Triangle6.java new file mode 100644 index 0000000..92bf2dc --- /dev/null +++ b/Chapter7/Triangle6.java @@ -0,0 +1,21 @@ + +public class Triangle6 extends TwoDShape6 { + + private String styleString; + + // A default constructor. + public Triangle6() { + // super(); + + styleString = "none"; + } + + double area() { + return getWidth() * getHeight() / 2; + } + + void showStyle() { + System.out.println("Triangle is " + styleString); + } + +} diff --git a/Chapter7/TwoDShape6.java b/Chapter7/TwoDShape6.java new file mode 100644 index 0000000..8a772ea --- /dev/null +++ b/Chapter7/TwoDShape6.java @@ -0,0 +1,45 @@ +// Add more constructors to TwoDShape +public class TwoDShape6 { + + private double width; + private double height; + + // A default constructor + public TwoDShape6() { + + width = height = 0.0; + } + + // Parameterized constructor. + TwoDShape6(double w, double h){ + width = w; + height = h; + } + + // Construct object with equal width and height. + TwoDShape6(double x){ + width = height = x; + } + + // Accessor methods for width and height. + double getWidth() { + return width; + } + + double getHeight() { + return height; + } + + void setWidth(double w) { + width = w; + } + + void setHeight(double h) { + height = h; + } + + void showDim() { + System.out.println("Width and height are " + width + " and " + height); + } + +}