Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Lab 2, you will explore the concepts of class composition. What is a point? A point has two coordinates x and y. If
In Lab 2, you will explore the concepts of class composition. What is a point? A point has two coordinates x and y. If we have two points, we can compute the distance between the two points. What is a line? A line has two points. If we have a line, we can get the length (distance) of that line. The following UML diagrams show the relationship of the two classes, and the main method: -intx -inty Point +Point() +Point(int x, int y) > +Point(Point p) +int getX() +int getY() +void set(int x, int y) -double distance(Point p) + double getDistance(Point p) 1..1 O+String toString( A 1..1 1..1 1..1 -p2- MainLab_2 -static Random rand -Point p1 -Point p2 + Line() + Line (Point p1, Point p2) +Line(Line aline) + double getDistance() +Point getP10) O+Point getP20 +void set(Point p1, Point p2) + String to String( -static int getInt() -static void getTwoPoints (Point p1, Point p2) + static void main(String] args) Implement the two classes based on the above UML diagrams. You can add in more methods but not remove any method from the UML. Line In the main method, you have to, randomly, generate a few Line objects and display the Line info. Some of the methods or info that I listed in the MainLab_2's UML, you need to implement and use them. For example, a method generates and returns a random integer; a method generates and returns the two random points. You can add in more methods Upon executing of your program, the following output will be displayed on the monitor screen: Set 1 Given Point (66, 36) Given Point (78, -83) Line (Point (66, 36), Point (78, -83), distance = 119.6035) Set 3 Given Point (52, 86) Given Point (70, 14) Line (Point (52, 86), Point (70, 14), distance = 74.2159) Set 2 Given Point (-13, 90) Given Point (39, 16) Line (Point (-13, 90), Point (39, 16), distance = 90.4434) Set 4 Given Point (89, 24) Given Point (23, -68) Line (Point (89, 24), Point (23, -68), distance = 113.2254) Set 5 Given Point (27, 84) Given Point (-27, -45) Line (Point (27, 84), Point (-27, -45), distance = 139.8463)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started