Gary Johnson

https://en.wikipedia.org/wiki/Heron%27s_formula

public class Point {
  int x, y;
  Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
  double distanceBetween(Point other) {
    return Math.sqrt( Math.pow(this.x - other.x, 2) +  
                      Math.pow(this.y - other.y, 2) ); 
  }
}

public class Line {
  Point a, b; 
  Line(Point a, Point b) {
    this.a = a;
    this.b = b; 
  }
  double length() {
    return this.a.distanceBetween(this.b);  
  }
}

public class Triangle {
  Line a, b, c;
  public Triangle(Point a, Point b, Point c) {
    // https://en.wikipedia.org/wiki/Heron%27s_formula
    this.a = new Line(b, c); 
    this.b = new Line(a, c); 
    this.c = new Line(a, b); 
  }
  double area() {
    double a = this.a.length(); 
    double b = this.b.length(); 
    double c = this.c.length(); 
    double s = (a + b + c) / 2; 
    return Math.sqrt( s * (s - a) * (s - b) * (s - c) ); 
  }
}

public class Circle {
  Point center;
  int radius;
  Circle(Point c, int r) {
    this.center = c;
    this.radius = r;
  }
  double area() {
    return Math.PI * Math.pow(this.radius, 2);  
  }
}

public class Rectangle {
  Point location; 
  int width, height; 
  Rectangle(Point a, int w, int h) {
    this.location = a;  
    this.width = w; 
    this.height = h; 
  }
  double area() {
    return this.width * this.height;  
  }
  
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Object[] shapes = new Object[3];
> shapes[0] = new Circle(new Point(4, 5), 6);
> shapes[0].area()
Static Error: No method in Object has name 'area'
> shapes[1] = new Rectangle(new Point(4, 5), 3, 12);
> shapes[1].area()
Static Error: No method in Object has name 'area'
> ((Rectangle)shapes[1]).area()
36.0


How else can I succeed? 

Team 7: Amara Kirk Mitch Mitch 
Team 6: Vaishali Menghan Alex Nicolas Jordan Josh 
Team 5: Drake Tianqi Chad Chetan Younghun Yuanyuan 
Team 4: Clarence Yixuan Elizabeth Rui Magdalena Sarah Tobias
Team 3: Skylar Chris Max Chris Levi Becca 
Team 2: Kendall Quinton Olivia Nova Yicheng Graham
Team 1: Justin Yiqin Jiahao Derek Glenn (*) Kyle McW

public class Shape {
  double area() {   
    return 4;
  } 
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Shape a = new Shape()
> a.area()
4.0
> Rectangle a = new Rectangle(new Point(4, 5), 6, 7);
> a.area()
42.0
> Shape b = new Rectangle(new Point(4, 5), 6, 7);
> b
Rectangle@34e76814
> b.area()
42.0


abstract class Shape {
  abstract double area();
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Shape a = new Shape()
Static Error: Cannot construct a Shape: a concrete class is required


Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Shape b = new Rectangle(new Point(4, 5), 6, 7);
> b.area()
42.0


Constructor chaining still is in effect. 

Next: interfaces and their relationship with abstract classes. 

public class Circle extends Shape {
  Point center;
  int radius;
  Circle(Point c, int r) {
    this.center = c;
    this.radius = r;
  }
  double area() {
    return Math.PI * Math.pow(this.radius, 2);  
  }
}

public class Rectangle extends Shape {
  Point location; 
  int width, height; 
  Rectangle(Point a, int w, int h) {
    this.location = a;  
    this.width = w; 
    this.height = h; 
  }
  double area() {
    return this.width * this.height;  
  }
  
}

public class Triangle extends Shape  {
  Line a, b, c;
  public Triangle(Point a, Point b, Point c) {
    // https://en.wikipedia.org/wiki/Heron%27s_formula
    this.a = new Line(b, c); 
    this.b = new Line(a, c); 
    this.c = new Line(a, b); 
  }
  double area() {
    double a = this.a.length(); 
    double b = this.b.length(); 
    double c = this.c.length(); 
    double s = (a + b + c) / 2; 
    return Math.sqrt( s * (s - a) * (s - b) * (s - c) ); 
  }
}

--