Implement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: MyTriangle.java, MyPoint.java.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Implement all the classes using Java programming language from the given UML Class diagram.
Note: This problem requires you to submit just two classes: MyTriangle.java, MyPoint.java.
Do NOT include "public static void main()" method inside all of these classes. The classes would be tested, using the unit-testing framework JUnit 4.
A class called MyTriangle, which models a triangle with 3 vertices, is designed as shown. The MyTriangle class uses three MyPoint instances (created in the earlier exercise) as its three vertices.
It contains:
- Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.
- A constructor that constructs a MyTriangle with three sets of coordinates, v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).
- An overloaded constructor that constructs a MyTriangle given three instances of MyPoint.
- A toString() method that returns a string description of the instance in the format "MyTriangle[v1=(x1,y1),v2=(x2,y2),v3=(x3,y3)]".
- A getPerimeter() method that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.
- A method printType(), which prints "equilateral" if all the three sides are equal, "isosceles" if any two of the three sides are equal, or "scalene" if the three sides are different.
Write the MyTriangle and MyPoint classes and submit as your solution.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps