Create a java application named distancecalculator

Assignment Help JAVA Programming
Reference no: EM131308498

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

Reference no: EM131308498

Questions Cloud

Find the size of a block when one address in the block : Write a method in Java to find the last address in the block when one of the addresses in the block is given as a string representing a CIDR notation.
Will the bank likely procreed with branch office project : Miami savings bank is considering the establishment of a new branch office at the corner of 59th street and collins ave. The savings association economics department projects annual operating revenues of $1.6m from fee incone and annual baranch opera..
Understand the difference between leadership and management : 1. Is it important for you as a manager to understand the difference between leadership and management? Explain your answer. 2. What is the difference between the "situational approach" and "trait approach" to leadership? What approach seems to hav..
Write a function that accepts as arguments : Write a function that accepts as arguments the following: A) An array of integers B) An integer that indicates the number of elements in the array The function should determine the mode of the array.
Create a java application named 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.
Is npv very much sensitive to the changes in the fixed costs : CB3410, Financial Management Assignment. How much in percentage of NPV changes in response to the increase/decrease in fixed costs? Plot NPV values for the different levels of fixed costs. Is NPV very much sensitive to the changes in the fixed cos..
How does the server know when all headers arrived : When an HTTP server receives a request message from an HTTP client, how does the server know when all headers have arrived and the body of the message is to follow?
Write a dim statement that declares a myfriend variable name : Write a Dim statement that declares a MyFriend variable named school. Write an assignment statement that assigns the value in the txtFirst control to the strFirst member.
Why should they be put in place : What basic principle of constitutional law must a police officer, but not always a probation officer, follow when conducting an ethical and legal search of a probationer's house? Explain why this law is applicable to this situation.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Which collection class allows you to access its elements

Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

  Design and code swing gui for a two-player tic-tac-toe game

If all nine cells have been filled without a winner the program should indicate that there was a tie.

  Text file containing the data

This program should begin by asking the user for the name of a text file containing the data. Then read the data which will be a line containing the dimensions of a 2 dimensional array followed by a 2 dimensional array of ints. Then perform variou..

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Program that allows the user to enter the last names

Write a program that allows the user to enter the last names of 5 candidates in a college election and the votes received by each candidate. The program should then output each candidates name, the votes reveived by that candidate

  Implement the structure that maintains a group of items

This class comprises a component of a larger game. You have been asked to implement the structure that maintains a group of items contained within a backpack

  Rewrite the following method using a while loop

Rewrite the following method using a while loop using an Iterator instead of the For each loop, files is an ArrayList storing String objects, also include ANY addition that you would need to have anywhere in the class.

  What things are you struggling to understand

Discuss your experiences with the programming assignment - what things are you struggling to understand?

  Create a constructor in the subclass why

Assume there is a base class with multiple constructors, if the subclass inherits from the base class, do we need to create a constructor in the subclass? Why?

  Describe principles of data abstraction and inheritance

Study the principles of data abstraction, inheritance and dynamic binding. Use Library to get started on finding resources.You must take the terms and describe it.

  Savingsaccount and bankaccount objects

The only differences between SavingsAccount and BankAccount objects is that SavingsAccount have an interest rate and can compute interest when necessary. Add an instance variable and a method to SavingsAccount to allow for these items.

  Values that occur just once

This list has some values that occur just once (1, 3, 4, 11, 13, 18), some values that occur twice (9, 16), some values that occur three times (14, 19) and a single value that occurs four times (7). Therefore, the call of list.maxCount() should re..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd