Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this program, input two points in the xy-coordinate system - first point: (x

ID: 667184 • Letter: F

Question

For this program, input two points in the xy-coordinate system -

first point: (x1, y1) and second point: (x2, y2), then

a) Compute the distance between them (rounded to 2 decimal places)
b) Determine the direction of travel from first point to second point

The directions of travel should translate to either N, S, E, W, NE, NW, SW, SE, ENE, NNE, NNW, WNW, WSW, SSW, SSE, or ESE

To find the direction of travel, you need to find an angle between the line from the first point to the second point and either

a line parallel to the x-axis OR

a line parallel to the y-axis

The angles run from 0-90 degrees in a counter-clockwise direction within each quadrant. For directions:

East to North: Quadrant I, use a line parallel x-axis

North to West: Quadrant II, use a line parallel y-axis

West to South: Quadrant III, use a line parallel x-axis

South to East: Quadrant IV, use a line parallel y-axis

To determine the direction, you need to know the quadrant and the angle. To determine the quadrant, you need to know the relative positions between x1 and x2 and between y1 and y2. The direction is in

Quadrant I:   when x2 > x1 and y2 >= y1

Quadrant II: when x2 <= x1 and y2 > y1

Quadrant III: when x2 < x1 and y2 <= y1

Quadrant IV: when x2 >= x1 and y2 < y1

The name of the class chould be ComputeDirections.Method names with parameters and what are they supposed to do are given below in the table:

Method

Parameters

Description

Called From

static

double

distance(…)

double x1,

double y1,

double x2,

double y2

Return the distance

from pt 1: (x1,y1) to pt 2: (x2,y2)

Round the answer to two decimal places

main

static

double

compAngle (…)

double side1,

double side2,

double side3

Return the angle at pt 1: (x1,y1) in degrees, where side 1 is across from pt 1: (x1,y1), side 2 is across from pt 2: (x2,y2) and side 3 is the path from pt 1 to pt 2

main

static

String compDirection(…)

double angle, int quadrant

Return the direction of travel using angle and quadrant

main

static

int

findQuadrant(…)

double x1,

double y1,

double x2,

double y2

Return the quadrant in which the direction of travel takes you

from (x1,y1) to (x2,y2)

return 1, 2, 3, or 4

main

static

void main(…)

String [] args

1.Prompt the user to enter two points

2.Find the quadrant

3.Use quadrant to find pt 3: (x3,y3)

4.Compute length of three sides

5.Compute the angle at pt 1

6.Compute the direction

7.Display the distance and direction

system

Method

Parameters

Description

Called From

static

double

distance(…)

double x1,

double y1,

double x2,

double y2

Return the distance

from pt 1: (x1,y1) to pt 2: (x2,y2)

Round the answer to two decimal places

main

static

double

compAngle (…)

double side1,

double side2,

double side3

Return the angle at pt 1: (x1,y1) in degrees, where side 1 is across from pt 1: (x1,y1), side 2 is across from pt 2: (x2,y2) and side 3 is the path from pt 1 to pt 2

main

static

String compDirection(…)

double angle, int quadrant

Return the direction of travel using angle and quadrant

main

static

int

findQuadrant(…)

double x1,

double y1,

double x2,

double y2

Return the quadrant in which the direction of travel takes you

from (x1,y1) to (x2,y2)

return 1, 2, 3, or 4

main

static

void main(…)

String [] args

1.Prompt the user to enter two points

2.Find the quadrant

3.Use quadrant to find pt 3: (x3,y3)

4.Compute length of three sides

5.Compute the angle at pt 1

6.Compute the direction

7.Display the distance and direction

system

Explanation / Answer

import java.util.Scanner;

public class ComputeDirections{
   static double distance(double x1, double y1, double x2,   double y2){
       double d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
       return Math.round(d * 100.0) / 100.0;
   }
   static double compAngle(double side1, double side2, double side3){
       return 180.0 / Math.PI * Math.acos((side2 * side2 + side3 * side3 - side1 * side1) / (2 * side2 * side3));
   }
   static String compDirection(double angle, int quadrant){
       // Please explain this method more. Cannot understand from just what is given!
   }
   static int findQuadrant(double x1, double y1, double x2, double y2){
       if(x2 > x1 && y2 >= y1) return 1;
       else if(x2 <= x1 && y2 > y1) return 2;
       else if(x2 < x1 && y2 <= y1) return 3;
       else return 4;
      
   }
   static void main(String [] args){
       double x1, y1, x2, y2;
       Scanner in = new Scanner(System.in);
       System.out.print("Enter 2 points(x1, y1, x2, y2): ");
       x1 = in.nextDouble();
       x2 = in.nextDouble();
       y1 = in.nextDouble();
       y2 = in.nextDouble();
       int quadrant = findQuadrant(x1, y1, x2, y2);
       // Please explain what to do more. What is point 3 and how is it calculated and stuff!
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote