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

This program will keep track of the total distance tor a trip through several ci

ID: 3687842 • Letter: T

Question

This program will keep track of the total distance tor a trip through several cities. js that we have cities 0, 1.2, and 3. We will enter the number for each city on the route as the program asks for each city from start to finish Assume that the distances are as follows Notice that only the distances for the bottom triangle of the table arc shown The assumption is that the distance between 2 cities does not depend on which direction you are going So. the program should use a ragged array, as described on page 290 of the textbook The program should perform as follows The program will ask for the starting point of the trip It will accept a number as the start of this step in the travel It will begin a loop which will: ask for the next stop in the trip stoic the user 's reply as the number for the slopping point copy the values of the starting and ending point>> into the values of variable r and c such that the aiue of r is greater than or equal to the value of c o use the values of i and c ( for row and column values) to find the next distance traveled and add it to the total distance o copy the value of the Hopping point into the vanable foi the starting point O ask if there is another city to visit get the reply from the user and if it is Y or 'y' go back to the top of the loop display the value of the total distance traveled

Explanation / Answer

This program will keep track of total distance for trip program the Floyd–Warshall algorithm is an algorithm for finding shortest paths in a weighted graph with positive or negative edge weights. Floyd-Warshall algorithm is a procedure, which is used to find the shorthest (longest) paths among all pairs of nodes in a graph, which does not contain any cycles of negative lenght. The main advantage of Floyd-Warshall algorithm is its simplicity import java.util.*; public class Cityroute { public static void main(String[] args) { Scanner scanner = new Scanner (System.in); LinkedList citiesList = new LinkedList(); LinkedList yList = new LinkedList(); LinkedList xList = new LinkedList(); String city = ""; double x = 0; double y = 0; int choice = 0; // First run to enter the starting location. System.out.println("Enter the name of the city:"); city = scanner.next(); citiesList.addFirst(city); System.out.println("Enter the X coordinate"); x = scanner.nextDouble(); xList.addFirst(x); System.out.println("Enter the Y coordinate"); y = scanner.nextDouble(); yList.addFirst(y); System.out.println("City: " + city + " X " + x + " Y " + y); System.out.println("CityList: " + citiesList + " X " + xList + " Y " + yList); System.out.println(); System.out.println("Pick one of the following choices:"); System.out.println(" 1. Enter another city"); System.out.println(" 2. Enter destination"); System.out.println(" 3. Exit"); System.out.println(); choice = scanner.nextInt(); while(choice == 1) { switch(choice) { // enter additional cities case 1: System.out.println("Enter the name of the city:"); city = scanner.next(); citiesList.add(city); System.out.println("Enter the X coordinate"); x = scanner.nextDouble(); xList.add(x); System.out.println("Enter the Y coordinate"); y = scanner.nextDouble(); yList.add(y); System.out.println("City: " + city + " X " + x + " Y " + y); System.out.println("CityList: " + citiesList + " X " + xList + " Y " + yList); // ask for next choice System.out.println(); System.out.println("Pick one of the following choices:"); System.out.println(" 1. Enter another city"); System.out.println(" 2. Enter destination"); System.out.println(" 3. Exit"); System.out.println(); choice = scanner.nextInt(); break; case 3: // Exit System.out.println("Good bye"); System.exit(0); break; }// end switch }// end loop // Enter final destination System.out.println("Enter your final destination:"); city = scanner.next(); citiesList.addLast(city); System.out.println("Enter the X coordinate"); x = scanner.nextDouble(); xList.addLast(x); System.out.println("Enter the Y coordinate"); y = scanner.nextDouble(); yList.addLast(y); System.out.println("City: " + city + " X " + x + " Y " + y); System.out.println("CityList: " + citiesList + " X " + xList + " Y " + yList); // Compute the distance between all the cities recursively, print all cities, and the total distance // between all cities. Not Sure How....????? double distance = 0; double endX = 0; double startX = 0; double endY = 0; double startY = 0; distance = Math.sqrt((endX-startX)*(endX-startX) + (endY-startY)*(endY-startY)); }// end main }//end class

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