Skip to main content

7. 📚 Home Task

The home task should be done using TypeScript.

info

The starter code for the home task is located in docs/2-building-blocks-of-oop-part-1/hometask folder

Specific Steps​

  1. Create a Point class, which creates 2 dimensional point with coordinates. It should contain:
  • two instance variables x and y;
  • default constructor which creates a point at the location of (0, 0);
  • overloaded constructor (use multiple constructors declaration for Typescript) which creates a point by x and y coordinates;
  • toString() method should return a Point class stringified representation in format: "(x, y)";
  • distance() method should be overloaded (use multiple methods declaration for Typescript) with next implementations:
    • no args: distance from this point to (0, 0);
    • distance(other: Point) - distance from this point to a given instance of Point;
    • distance(x, y) - distance from this point to a given point (x, y).
  1. Create abstract superclass called Shape, which contains:
  • two protected instance variables: color (string), filled (boolean) and points (Point[]);
  • overloaded constructor (use multiple constructors declaration for Typescript): a constructor that takes a list of points and initializes the color to "green" and filled to true by default, and a constructor that takes a list of points, the color and filled properties;
  • Make sure that the Shape has at least 3 points (2 points is just a line).
  • toString() method that returns "A Shape with color of xxx and filled/Not filled. Points: (x1, y1), (x2, y2)...";
  • getPerimeter() that calculates the perimeter using Point.distance method;
  1. Create class Triangle that takes 3 points as it's vertices. Triangle must inherit Shape abstract class. Triangle should contain:
  • a constructor (use multiple constructors declaration for Typescript) which creates Triangle class using three instances of Point class, may also provide color and filled properties;
  • override toString() method, it should return a Triangle class stringified representation in format "Triangle[v1=(x1, y1),v2=(x2, y2),v3=(x3, y3)]";
  • override getType() method, which prints "equilateral triangle" if all the three sides are equal, "isosceles triangle" if any two of the three sides are equal, or "scalene triangle" if all sides are different.

Evaluation criteria​

  1. Only some classes were implemented.
  2. Some classes were not implemented.
  3. Some required methods are missing.
  4. All tasks are implemented to a full extend.