Computers and Technology

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 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
// 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 onc }
// 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 (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
Information for finding Quadrants Information for finding distance c o po = √(x2 − x1 ) 2 + (y2 − y1 ) 2 You may also need the method in the Math class: Math. sqrt(num) and/or Math. pow(base, exponent)

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 00:30, lesok0818
Advantages and disadvantages of binary system
Answers: 1
image
Computers and Technology, 23.06.2019 22:50, christingle2004
What is an rss reader used for? for creating a user account on a social new site
Answers: 2
image
Computers and Technology, 24.06.2019 12:30, nomood
Select all that apply. what two keys listed below should you use to enter data in an excel worksheet? tab backspace enter right arrow
Answers: 2
image
Computers and Technology, 25.06.2019 04:10, asdasddas776
This might be a bit off-topic, but i'm having trouble with a certain arg made by game theory. if there are any theorists out there that wanna , it would be appreciated!
Answers: 2
Do you know the correct answer?
In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as you...

Questions in other subjects:

Konu
Biology, 28.09.2019 22:30
Konu
Arts, 28.09.2019 22:30
Konu
Mathematics, 28.09.2019 22:30