Created
February 26, 2018 07:35
-
-
Save annibuliful/cfc36064192f3468f4979f2c4b07286e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package week7; | |
| public class Rectangle extends Shape { | |
| double length; | |
| double width; | |
| public Rectangle() { | |
| super.getColor(); | |
| } | |
| public Rectangle(String color, double length, double width) { | |
| super.setColor(color); | |
| this.length = length; | |
| this.width = width; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Rectangle" + "[" + "length=" + this.length + "," + "width=" + this.width + "," + "Shape" + "[" | |
| + "color=" + super.getColor() + "]" + "]"; | |
| } | |
| // Override the inherited getArea() to provide the proper implementation | |
| @Override | |
| public double getArea() { | |
| double area = this.length * this.width; | |
| return area; | |
| } | |
| public double getArea(double length, double width) { | |
| this.length = length; | |
| this.width = width; | |
| return getArea(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package week7; | |
| public class Triangle extends Shape { | |
| private double base; | |
| private double height; | |
| public Triangle() { | |
| super.getColor(); | |
| } | |
| public Triangle(String color, double base, double height) { | |
| super.setColor(color); | |
| this.base = base; | |
| this.height = height; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Rectangle" + "[" + "base=" + this.base + "," + "height=" + this.height + "," + "Shape" + "[" + "color=" | |
| + super.getColor() + "]" + "]"; | |
| } | |
| // Override the inherited getArea() to provide the proper implementation | |
| @Override | |
| public double getArea() { | |
| double area = 0.5 * this.base * this.height; | |
| return area; | |
| } | |
| public double getArea(double base, double height) { | |
| this.base = base; | |
| this.height = height; | |
| return getArea(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment