Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a set of cities, the central city is the city that has the shortest total distance to all other cities. Write a program (

Given a set of cities, the central city is the city that has the shortest total distance to all

other cities. Write a program (

CentralCity.java

) that prompts the user to enter the

number of the cities and the locations of the cities (x and y coordinates), stores the

locations into a n-by-2 matrix where n is the number of the cities, and finds the central

city and its total distance to all other cities. Here is a sample run:

Enter the number of cities: 5

Enter the coordinates of the cities: 2.5 5 5.1 3 1 9 5.4 54 5.5 2.1

The central city is at (2.50, 5.00).

The total distance to all other cities is 60.81.

You are required to write two methods with the following headers, respectively:

// return distance between two points c1 and c2

public static double distance(double [] c1, double [] c2)

// return the total distance of a specific city to all other cities

// where cities contains all cities, and

i

is the index for a specific city

public static double totalDistance(double [][] cities, int i)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions