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.

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

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.

MyTriangle
МуРoint
3
-v1:MyPoint
-v2:MyPoint
-v3:MyPoint
-x:int
vertices -y:int
+MyTriangle(x1:int,y1:int,
x2:int,y2:int,x3:int,
у3:int)
+MyTriangle(v1:MyPoint,
v2:MyPoint, v3: MyPoińt)
+toString():String •
+getPerimeter():double.
+getType ():String
"MyTriangle[v1=(x1,y1),v2=(x2,y2),v3=(x3,y3)]"
Use MyPoint's distance() to compute
the length of the edges.
"Equilateral" or "Isosceles" or "Scalene"
Transcribed Image Text:MyTriangle МуРoint 3 -v1:MyPoint -v2:MyPoint -v3:MyPoint -x:int vertices -y:int +MyTriangle(x1:int,y1:int, x2:int,y2:int,x3:int, у3:int) +MyTriangle(v1:MyPoint, v2:MyPoint, v3: MyPoińt) +toString():String • +getPerimeter():double. +getType ():String "MyTriangle[v1=(x1,y1),v2=(x2,y2),v3=(x3,y3)]" Use MyPoint's distance() to compute the length of the edges. "Equilateral" or "Isosceles" or "Scalene"
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage