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​
- Create a
Pointclass, which creates 2 dimensional point with coordinates. It should contain:
- two instance variables
xandy; - 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
xandycoordinates; toString()method should return aPointclass 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 ofPoint;distance(x, y)- distance from this point to a given point (x, y).
- Create abstract superclass called
Shape, which contains:
- two protected instance variables:
color(string),filled(boolean) andpoints(Point[]); - overloaded constructor (use multiple constructors declaration for Typescript): a
constructor that takes a list of
pointsand initializes the color to"green"and filled totrueby default, and a constructor that takes a list ofpoints, thecolorandfilledproperties; - Make sure that the
Shapehas 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 usingPoint.distancemethod;
- Create class
Trianglethat takes 3 points as it's vertices. Triangle must inheritShapeabstract class.Triangleshould contain:
- a constructor (use multiple constructors declaration for Typescript) which creates
Triangleclass using three instances ofPointclass, may also provide color and filled properties; - override
toString()method, it should return aTriangleclass 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​
- Only some classes were implemented.
- Some classes were not implemented.
- Some required methods are missing.
- All tasks are implemented to a full extend.