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
Point
class, which creates 2 dimensional point with coordinates. It should contain:
- two instance variables
x
andy
; - 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
andy
coordinates; toString()
method should return aPoint
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 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
points
and initializes the color to"green"
and filled totrue
by default, and a constructor that takes a list ofpoints
, thecolor
andfilled
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 usingPoint.distance
method;
- Create class
Triangle
that takes 3 points as it's vertices. Triangle must inheritShape
abstract class.Triangle
should contain:
- a constructor (use multiple constructors declaration for Typescript) which creates
Triangle
class using three instances ofPoint
class, may also provide color and filled properties; - override
toString()
method, it should return aTriangle
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​
- Only some classes were implemented.
- Some classes were not implemented.
- Some required methods are missing.
- All tasks are implemented to a full extend.