In order to correctly handle this, you can create a cities class that has the city name and time difference. You can then add the cities object an arraylist. Once you prompt the user for input, you can search the arraylist checking if the city name matches the user input. Once a match is found you can retrieve that city object and get it's timedifference and get the actual time since eastern time is know.
Henry Z.
asked 12/16/22java question.
DATA BLOCK - city list and time difference from EST
String[] cities = { "London", "Paris", "Rome", "Seattle", "Tokyo" };
int[] timeDeltas = { 6, 7, 8, -3, -12 };
// TODO: create the ArrayList of TimeDifference objects using
new operator
// TODO: load the array list with the data with a regular for loop
//for (int i = 0; i < cities.length; i++)
{
// TODO: instantiate each TimeDifference object and add it
the ArrayList
}
// TODO: create Scanner object
// create a variable to hold a Time object reference
Time inputTime;
// prompt for a valid current time
inputTime = getValidTime(input);
// flush input buffer stream
input.nextLine();
// TODO: prompt for desired city name and receive input String
// TODO: loop to prompt user for city and call findCityTime or quit
Follow
2
Add comment
More
Report
1 Expert Answer
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.