(Solved) : Included Whole Lab Part Need Help Coding String Compdirection Using Table Ii Bolded Easier Q26207949 . . .
I have included the whole lab, but the part I need helpon is coding String CompDirection using Table II (it is boldedbelow for easier reading)- please include comments and keep it assimple as possible because I am a beginner and need/want tounderstand. Thank you! Also, feel free to code the whole program,but again the part I can’t figure out at all is the StringCompDirection using Table II.
For this program, the input is two points in a xy-plane. Eachpoint is specified by providing their x and y-coordinates: Point 1:(x1, y1) and Point 2: (x2, y2). The program will then: a) Computethe distance between the 2 points b) Determine the direction oftravel from point 1 to point 2 The directions of travel shouldtranslate to either N, S, E, W, NE, NW, SW, SE, ENE, NNE, NNW, WNW,WSW, SSW, SSE, or ESE.
// Sample output for point (3, 3) and (-8, 2) Enter x and ycoordinates of two points: Point 1: (x1, y1) x1 = 3 y1 = 3 Point 2:(x2, y2) x2 = -8 y2 = 2 The distance between these points: 11.05The direction traveled from the first point to the second: W
The main method is used to request input and to call theappropriate methods described below in order to report the distanceand direction. Code main using the following algorithm. Prompt theuser to enter two points Find the quadrant by calling thefindQuadrant method, passing in the x1, y1, x2 and y2 valuesentered by user. Use the found quadrant to find pt 3: (x3,y3): ForQuad I and Quad III:x3 = x2 and y3 = y1 For Quad II and Quad IV: x3= x1 and y3 = y2 Compute length of three sides, by calling thedistance method for each side with the appropriate parameteres.Compute the angle A at point 1, by calling the compAngle method,which uses the Law of Cosines. See ComputeAngles.java code. Computethe direction by calling the compDirection method Display thedistance and direction. Round the distance to two decimal placesbefore displaying it. The ComputeAngles.java code shows you how todo this rounding.
Code the other methods as follows:
Method Parameters Description static double distance(…) doublex1, double y1, double x2, double y2 Return the distance from P1:(x1, y1) to P2: (x2, y2) See ComputeAngles.java code.
static double compAngle (…) double sideA, double sideB, doublesideC Return the angle at P1: (x1, y1) in degrees, where sideA isacross from P1: (x1, y1), sideB is across from P2: (x2, y2) andsideC is across from P3: (x3, y3) See ComputeAngles.java code.
static String compDirection(…) double angle, intquadrant Return the direction of travel using the angle andquadrant. This can be coded using a switch block based on quadrantand within each of the four cases, five if/else blocks thatdetermine the direction. Table 2 above gives the angle intervals tocheck for each direction
Table 2: Direction Intervals WithinQuadrants
Quadrant
Direction
Angle Interval
From Axis
I
E
(00.00, 11.25]
+ x-axis
I
ENE
(11.25, 33.75]
+ x-axis
I
NE
(33.75, 56.25]
+ x-axis
I
NNE
(56.25, 78.75]
+ x-axis
I
N
(78.75, 90.00]
+ x-axis
II
N
(00.00, 11.25]
+ y-axis
II
NNW
(11.25, 33.75]
+ y-axis
II
NW
(33.75, 56.25]
+ y-axis
II
WNW
(56.25, 78.75]
+ y-axis
II
W
(78.75, 90.00]
+ y-axis
III
W
(00.00, 11.25]
– x-axis
III
WSW
(11.25, 33.75]
– x-axis
III
SW
(33.75, 56.25]
– x-axis
III
SSW
(56.25, 78.75]
– x-axis
III
S
(78.75, 90.00]
– x-axis
IV
S
(00.00, 11.25]
– y-axis
IV
SSE
(11.25, 33.75]
– y-axis
IV
SE
(33.75, 56.25]
– y-axis
IV
ESE
(56.25, 78.75]
– y-axis
IV
E
(78.75, 90.00]
– y-axis
static int findQuadrant(…) double x1, double y1, double x2,double y2 Return the quadrant in which the direction of traveltakes you from (x1,y1) to (x2,y2). Quads: Q1: when x2 > x1 andy2 >= y1 Q2: when x2 <= x1 and y2 > y1 Q3: when x2 < x1and y2 <= y1 Q4: when x2 >= x1 and y2 < y1 return 1, 2, 3,or 4
static void main(…) String [] args See above
**ComputeAngles.java code:
import java.util.Scanner;
public class ComputeAngles {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter three points
System.out.print(“Enter three points: “);
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
// Compute three sides
double a = Math.sqrt((x2 – x3) * (x2 – x3) + (y2 – y3) * (y2 -y3));
double b = Math.sqrt((x1 – x3) * (x1 – x3) + (y1 – y3) * (y1 -y3));
double c = Math.sqrt((x1 – x2) * (x1 – x2) + (y1 – y2) * (y1 -y2));
// Compute three angles
double A = Math.toDegrees(Math.acos((a * a – b * b – c * c) / (-2 *b * c)));
double B = Math.toDegrees(Math.acos((b * b – a * a – c * c) / (-2 *a * c)));
double C = Math.toDegrees(Math.acos((c * c – b * b – a * a) / (-2 *a * b)));
// Display results
System.out.println(“The three angles are ” + Math.round(A * 100) /100.0 + ” ” + Math.round(B * 100) / 100.0 + ” ” + Math.round(C *100) / 100.0); } }
Expert Answer
Answer to Included Whole Lab Part Need Help Coding String Compdirection Using Table Ii Bolded Easier Q26207949 . . .
OR