ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 107 Weeks Ago, 5 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Accounting Posted 20 May 2017 My Price 9.00

JAVA_HA8.1: Central

What I have:

import java.util.Scanner;
public class CentralCities {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter the number of cities: ");
int numberOfCities = input.nextInt();

double [][] cities = new double[numberOfCities][2];

System.out.print("Enter the coordinates of the cities: ");
for(int row = 0; row for(int column = 0; column cities[row][column] = input.nextDouble();
}
}

System.out.printf("The central city is at (%.2f, %.2f).n" , cities[0][1]);
//System.out.printf("The total distance from the central city to all other cities is %.2f." , totalDistance);
}

public static double distance(double [] c1, double [] c2){
double distance = Math.sqrt((c2[0] - c1[0]) * (c2[0] - c1[0]) + (c2[1] - c1[1]) * (c2[1] - c1[1]));
return distance;
}

public static double totalDistance(double [][] cities, int i){
double totalDistance = 0;
for(int row = 0; row {
totalDistance += distance(cities[row], cities[i]);
}
return totalDistance;
}
}

 

JAVA_HA8.1: Central CityGiven a set of cities, the central city is the city that has the shortest total distance to allother cities. Write a program (CentralCity.java) that prompts the user to enter thenumber of the cities and the locations of the cities (x and y coordinates), stores thelocations into a n-by-2 matrix where n is the number of the cities, and finds the centralcity and its total distance to all other cities. Here is a sample run:Enter the number of cities:5Enter the coordinates of the cities:2.5 5 5.1 3 1 9 5.4 54 5.5 2.1The central city is at (2.50, 5.00).The total distance from the central city 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 c2public static double distance(double [] c1, double [] c2)// return the total distance of a specific city to all other cities// where cities contains all cities, andiis the index for a specific citypublic static double totalDistance(double [][] cities, int i)Submit the source code fileCentralCity.javato drop box HA8.1.

Attachments:

Answers

(11)
Status NEW Posted 20 May 2017 11:05 AM My Price 9.00

-----------

Attachments

file 1495278397-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)