In Java please
10.9 Lab 6
In BlueJ, create a project called Lab6
Create a class called LineSegment –Note: test changes as you go
Copy the code for LineSegment given below into the class.
Take a few minutes to understand what the class does. Besides the mutators and accessors, it has a method called print, that prints the end points of the line segment in the form: (x, y) to (x, y)
You will have to write two methods in the LineSegment class. There is information on black board under this week to help with the following methods.
determineQuadrant - this method determines if the line segment is completely in a quadrant and returns a String (“Quadrant 1”, “Quadrant 2”, “Quadrant 3”, or “Quadrant 4”) representing the quadrant. If it is not completely in a quadrant it returns the string “Crosses an Axis”. There are no formal parameters.
computeLength– returns the length of the line segment created by the points. There are no formal parameters
• Test the line segment class to make sure the methods you added work correctly.
Code for class LineSegment
public class LineSegment
{
private int x1;
private int y1;
private int x2;
private int y2;
public LineSegment()
{
}
public LineSegment(int x1, int y1, int x2, int y2)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public void setPoint1(int x, int y)
{
this.x1 = x;
this.y1 = y;
}
public void setPoint2(int x, int y)
{
this.x2 = x;
this.y2 = y;
}
public int getPoint1X()
{
return x1;
}
public int getPoint1Y()
{
return y1;
}
public int getPoint2X()
{
return x2;
}
public int getPoint2Y()
{
return y2;
}
//Prints the point in the format (x1, y1) to (x2, y2)
public void print()
{
System.out.print("(" + x1 + ", " + y1 + ") to (" + x2 + ", " + y2 + ")");
}
}
Once you have the class working
Create a class called Main – copy the code below into the class
Follow the comments to write the main method and the enterLineSegmentEndPoints in the Main class.
The program, when finished, should create the output given
When you have it running correctly, upload the LineSegment and Main class to zybook and submit it for grading.
Code for class Main
import java.util.Scanner;
public class Main
{
public static Scanner kb = new Scanner(System.in);
public static void main(String [] args)
{
String input; // this variable used to allow the
// use to type Y or N when asked about
// changing point
// As you develop your program, add any variables
// you may need here
// Declare an object of the Line Segment class
// Use the constructor with no formal parameters
// You are to finish the rest of main to create the output given.
// This program will also have a method called enterLineSegmentEndPoints
// that allows the user to enter the end points of a line segment. The header
// for the method is given below main.
// Declare any variables you may need in the section above
// Some suggestions might be:
// First get the loop going that will continue asking if there is
// another line segment until the user types in anything other than Y
// Next get the method to enter the endpoints working - see output for formatting
// Then compute the length of the line segment using the method you wrote in the class
// Next for the quadrant, you might want to store the string returned from the method
// class and then check the first character to determine what to print
// Finally put in the code that will print the total number of line segments
// entered after the user indicates they are done.
// NOTE: Get little pieces to work at a time - do NOT type it all in at once
}
// Add the code to this method wrapper so that it allows the user to enter the
// end points of the line segments as shown on the output
public static void enterLineSegmentEndPoints(LineSegment line)
{
}
}
A sample output is given
Enter the x and y coordinate of the first end point: 2 9
Enter the x and y coordinate of the second end point: 14 6
Line Segment: (2, 9) to (14, 6)
The length of the line segment is: 12.37
The line segment is completely in Quadrant 1
Would you like to enter another line segment (y/n): Y
Enter the x and y coordinate of the first end point: -4 8
Enter the x and y coordinate of the second end point: -7 -3
Line Segment: (-4, 8) to (-7, -3)
The length of the line segment is: 11.40
The line segment Crosses an Axis
Would you like to enter another line segment (y/n): y
Enter the x and y coordinate of the first end point: 3 -7
Enter the x and y coordinate of the second end point: 21 -14
Line Segment: (3, -7) to (21, -14)
The length of the line segment is: 19.31
The line segment is completely in Quadrant 4
Would you like to enter another line segment (y/n): n
You entered a total of 3 line segments
Answers
Answered by
2
Answer:
wbwbwhsjejjjdjkkwjejkwiwn
Similar questions
India Languages,
3 months ago
Political Science,
3 months ago
English,
6 months ago
Science,
10 months ago