Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Java language 2. Write a class from the following UML diagram: Point - - X: int y:int z: int + Point l/should create the
Using Java language
2. Write a class from the following UML diagram: Point - - X: int y:int z: int + Point l/should create the origin (0,0) + Point (x: int, y: int) //should create (x,y,0) + Point (x: int, y:int, z: int) //should create (x,y,z) + distance (Point p): double //should return the distance between the 2 points + distance From Origin : double //should return the distance from (0,0) + toString(): String //should return the point in the form "(x,y,z)" + equals (Point p): boolean 1/2 points are equal if x,y,z values are all equal + translate (x: int, y: int): Point + translate (x: int, y:int, z: int) : Point (Hint: remember to add the get and set methods) Distance between two points is: (x1 - x)2 + (- y2)2 + (21-22) Translating a point is: creating a new point where the x value is the x of the original point plus the parameter, similarly for y and z. Ex. P =(3, -6) and we want to use translate (1, 2) then we should get P2 =(4,-4) 3. Now you will make a class Line. Should Line extend Point? Why? Should Point extend Line? Why? Should Line have attributes that are Points? Why? Line - start: Point - end : Point - length : double + Line ( 1/makes line with start (0,0) and end (1,1) Line (s: Point, e: Point) + midpoint (: Point + slope(): double + toString(): String // "The line starts at (x,y) and ends at (x2,y2) The length is # + equals (Point p): boolean For a line we can assume we will only use the x and y coordinates. Length of a line is the same as the distance between its two endpoints. (Hint: This should be assigned using a method call to a method that should already exist at this point.) Midpoint of a line: M = ***82, Voty) Slope of a line s = y2-Y X2-X1 4. Now we are going to add an exception to the line class. A valid line must have a length > 0. In other words, the length of a line cannot be zero. 5. Look at Test.java and read through the main method. Try to see what is happening with all the try/catch blocks 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