Question

Page > of 2 0 Write algorithm for a program that will prompt user to enter...

Write algorithm for a program that will prompt user to enter x and y coordinates of two points : (x1, y1) and (x2, y2) the calculate the distance between these two points. 

image.png

For example, if the two points are as shown below, then distance d can be evaluated using the formula below. 


Formula for this distance d is:

image.png

Submit printout - with your name on top. 


Question 2 

Implement the algorithm above in Java 

Submit printout of source code - with your name on top. Also a screenshot of ONE run of your program. 

Also a screenshot of ONE run of your program.


5 0
Add a comment Improve this question Transcribed image text
Answer #1

*******************************************CODE**************************************

import java.util.*;
public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   System.out.println("Enter the (x1,y1):");
   int x1 =sc.nextInt();
   int y1 =sc.nextInt();
   System.out.println("Enter the (x2,y2):");
   int x2 =sc.nextInt();
   int y2 =sc.nextInt();
  
   double distance = Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2));
   System.out.println("Distance: " + distance);
  
   }
}

Code Screenshot:

Main.java 1 import java.util.*; 2 public class Main 3- { public static void main(String[] args) { Scanner sc = new Scanner(Sy

Output Screenshot:

Enter the (x1, y1): 13 Enter the (x2,Y2): 24. Distance: 1.4142135623730951 ... Program finished with exit code 0, Press ENTER

Please upvote the answer if you find it useful and comment down below for any queries.

Add a comment
Know the answer?
Add Answer to:
Page > of 2 0 Write algorithm for a program that will prompt user to enter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and...

    programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and verify the result by choosing some test data. Prompt user to write X1 value in double Read X1 Prompt user to write X2 value in double Read X2 Prompt user to write Y1 value in double Read Y1 Prompt user to write Y2 value in double Read Y2 Compute the lengths of the two sides of the right triangle generated by the two points...

  • Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3,...

    Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the distance of two points (x1, y1) and (x2, y2) is d = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); or d = Math.pow((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1), 0.5); The formula for computing the...

  • The straight-line distance of two points (x1, y1) and (x2, y2) in a Cartesian plane can be calculated by the formula: Distance of two points Your task is to create an algorithm using flowchart to solve this problem

    The straight-line distance of two points (x1, y1) and (x2, y2) in a Cartesian plane can be calculated by the formula:Your task is to create an algorithm using flowchart to solve this problem. in your algorithm, you need to prompt user to enter the value of x1, x2. y1 and y2.

  • Hello, could someone please create me this MATLAB program GUI: - An example of the output...

    Hello, could someone please create me this MATLAB program GUI: - An example of the output is on the bottom *Please also generate a graph of the Equation y=mx+b upon pressing Calculate* Thank you Online calculator to find slope, length/distance, angle and equation of a line segment for entered the coordinates (X1, y1), (X2, y2) of two points, using following formula : m = (y2-71)/(x2-x1) and Distance = V((x2-x1)2 + (y2-71)2) Angle = arctan (m) and Line of Equation is...

  • Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds...

    Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds the sum and average of a series of numbers he program should first prompt the user to enter total numbers of numbers are to be summed and averaged. It should then as for input for each of the numbers, add them, and print the total of the numbers and their average 2. Write a progra m that finds the area of a circle. The...

  • 1(a)    Write a python program using a function name slope(x1, y1, x2, y2) that returns...

    1(a)    Write a python program using a function name slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). 1(b) For problem 1(a), write a python program using a function name Euclidean_dist(x1, y1, x2, y2) which will calculate and return the Euclidean distance between the points (x1, y1) and (x2, y2).

  • Collassa Question 2 Not yet ansered Merced out of 2000 OP Write a program to calculate...

    Collassa Question 2 Not yet ansered Merced out of 2000 OP Write a program to calculate the distance between the two points. Note: x1, y1, 22. 72 are all double values. You can use the following formula to calculate the distance between the two points. (x2 - x)2 + (y2 – y,)? Sample run: Input xd: 25 Input yl: 15 Input x2: 35 Input y2: 10 Distance betieen the said points: 11.1883 tnopalam hilarati

  • Implement the Point class (code for this up to the isHigher method was discussed in the...

    Implement the Point class (code for this up to the isHigher method was discussed in the lecture). The class has the following instance variables: • x coordinate (an int) • y coordinate (an int) and the following methods: • Constructor that sets the x and y coordinates • Get and set methods • Method equals if this point is equal to another point object (if the x and y coordinates are the same). • Method isHigher if this point is...

  • cs 101-03/05 computers & programming, Due: 04/18/2019 (sharp) Programming Horneworkr, Modules Make sure to include your...

    cs 101-03/05 computers & programming, Due: 04/18/2019 (sharp) Programming Horneworkr, Modules Make sure to include your name, section and the homwo program as shown below: # Name # CS 101-03/05 Homework 7 Make sure to test your program before submit . Distance between two points P(x1, yi) and Qlx2, y2) in a straight line is iven by V(x2-x1)2 + (y2-y1)2 and the Slope of a straight line is given by:m (y2-y:) /(2-x), where Pll. yl and two points on the...

  • Pleass write Java Program with comments. For this peoblem it supposed to create ur own list of po...

    Pleass write Java Program with comments. For this peoblem it supposed to create ur own list of points, then use that list to find the closest point. A list of points and the points have x and y values such as [(1,2),(3,5),(6,7),....] that’s just example. Implement the algorithm to meet the following requirements Define a class named Pair with data fields pl and p2 to represent two points and a method named getDistance) that returns the distance between the two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT