Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Java Application - DistanceCalculator

Create a Java application named DistanceCalculator.java to solve the following problem.

An application is needed to allow a user to enter two cities and display the distances between them.

A text file named CityDistances.txt contains the names of cities and the distances between each city. The file has the following contents:

7
Chicago,0,983,787,714,1375,967,1087
Boston,983,0,214,1102,1763,1723,1842
New York,787,214,0,888,1549,1548,1627
Atlanta,714,1102,888,0,661,781,810
Miami,1375,1763,1549,661,0,1426,1187
Dallas,967,1723,1548,781,1426,0,239
Houston,1087,1842,1627,810,1187,239,0
Notice that the file tokens are delimited by commas.

The first number in the file is the number of cities. The next lines contain the city names and the distances between cities that can be used to create a two dimension array to model the distance table shown on the previous page.

Your application should read the cities into a one dimensional array and the distances into a two dimensional array.

After the arrays are created, display the number of cities and a list of cities and then prompt the user to enter two cities and then display the distances between the two cities. Validate the user input to not allow invalid cities to be entered. Create a loop to continue prompting until the user wants to exit the program.

Use fields to hold the city names array and the distances array.

Use modular programming. I suggest a method to load the arrays from the file, and a method to retrieve the city numbers and display the distance.

Program output might look like this:

Number of cities 7
City number 1 Chicago
City number 2 Boston
City number 3 New York
City number 4 Atlanta
City number 5 Miami
City number 6 Dallas
City number 7 Houston

Distance from city number: 2
To city number: 5
Boston to Miami 1763 miles
Continue (yes/no)yes

Distance from city number: 1
To city number: 7
Chicago to Houston 1087 miles
Continue (yes/no)no
Name the Java Class: DistanceCalculator

Java, Programming

  • Category:- Java
  • Reference No.:- M92063127
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Java

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As