Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use this code to make the rest public class Point { /** The location of the point in the X direction. */ private double

Please use this code to make the rest
public class Point
{
/** The location of the point in the X direction. */
private double x;
/** The location of the point in the Y direction. */
private double y;
/** Constructs a Point from given x and y values.
@param xIn The location of the Point in the X direction.
@param yIn The location of the Point in the Y direction.
*/
public Point(double xIn, double yIn)
{ x = xIn;
y = yIn;
}
/** Returns the x value for this Point.
@return The x value for this Point.
*/
public double getX()
{ return x;
}
/** Returns the y value for this Point.
@return The y value for this Point.
*/
public double getY()
{ return y;
}
/** Calculates the distance between this Point and
another Point using the pythagorean theorem
@param other The other Point.
@return The distance between this Point and
another Point.
*/
public double distance (Point other)
{ double dx = x - other.getX();
double dy = y - other.getY();
return Math.sqrt(dx*dx + dy*dy);
}
// What is the Math class?
// Math.sqrt is a static method
// Find & use the Java API documentation
// ==> Use 'javac -version'
// ==> Then Google: jdk (your version number) api
// Bookmark that page!
/** Returns a String representation of the x and y values
for this Point.
@return A String representation of the x and y values
for this Point.
*/
public String toString()
{ return "Point[x=" + x + ", y=" + y + "]";
}
/** Changes the x value for this Point.
@param xIn The new x value.
*/
public void setX(double xIn)
{ x = xIn;
}
/** Changes the y value for this Point.
@param yIn The new y value.
*/
public void setY(double yIn)
{ y = yIn;
}
}
image text in transcribed
image text in transcribed
image text in transcribed
Part B: Line Segments Download the Point.java file, which is available for download with this assignment on Desire2Learn. (This is the same class that was used in Module 5 and is also available for download there.) You do not need to change this file. You will use this class to help create a LineSegment class and an associated test driver. It is highly recommended that you use incremental programming to complete this program, where you code a little, try to compile and run what you have so far, and repeat until done. Write a complete LineSegment class. A LineSegment is defined by its two endpoints, each of which is represented by a Point object. Create two constructors - one that receives two Point objects, and the other that receives the four x and y values required for the constructor to create two Point objects. Include an accessor method for each of the two endpoints. Also include the following three methods: isParalleiTo ( ) - Returns true if this line segment is parallel to another line segment. The other line segment is given as a parameter to this method. Two line segments are parallel if they have the same slope. Be careful with vertical lines, where the slope is undefined because calculating such a slope would require division by zero. Your method must handle vertical lines. (Hint: One way to do this is to perform your calculations in such a way that no divisions are necessary. Another possible solution would be to use an if statement to detect when you have a vertical line, prior to attempting any slope calculations.) Can't remember how to calculate the slope of a line segment? Google itt length() - Returns the length of this line segment. You can use the distance method in the Point class to help with this calculation. midpoint( ) - Returns a Point representing the midpoint of this line segment. Can't remember how to find the midpoint of a line segment? Google it! Add javadoc comments to the LineSegment class. Include a javadoc comment for the class, and for each of its instance variables and methods (including the constructors). Include @author, @param, and @return tags where appropriate. You may wish to run javadoc to check that your comments are correctly formatted. However, you do not need to submit the files obtained by running the javadoc command. In a separate LineTest class, create a test driver that tests each of the methods in your LineSegment class, induding the accessors for the two endpoints, as well as both constructors. Use the following line segments as test data: Line Segment 1: (0.0,0.0) to (0.0,5.0) Line Segment 2: (2.0.5.0) to (2.0,7.0) Line Segment 3:(1.0,5.0) to (6.0,5.0) Line Segment 4:(2.0,5.0) to (7.3,10.1) Line Segment 5:(0.0,3.0) to (10.6,7.2) Line Segment 6: (0.0,3.0) to (10.6,3.0) Line Segment 7: (2.0,5.0) to (2.0,5.0) For the isParallerTo method, include test cases for each of the following: - Line segments 1 and 2. - Line segments 1 and 3 . - Line segments 4 and 5. - Line segments 4 and 6. - Line segment 4 compared with itself (yes, this is considered parallel). For each test case for the isParalleiTo() method, use an if-else statement in your test driver to print whether or not the two line segments were found to be parallel. All output should include enough information so you can identify which line segments are involved in each test case. For both the midpoint and length methods, include test cases for each of the following: - Line segment 1 - Line segment 3 - Line segment 4 - Line segment 7 It is okay to use the Point toString() method for displaying midpoint results. For each test case, you must print sufficient information to allow you to confirm that the test case performed as expected

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions