Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Created February 26, 2018 07:35
Show Gist options
  • Select an option

  • Save annibuliful/cfc36064192f3468f4979f2c4b07286e to your computer and use it in GitHub Desktop.

Select an option

Save annibuliful/cfc36064192f3468f4979f2c4b07286e to your computer and use it in GitHub Desktop.
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();
}
}
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