Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Write a java program

Write a program to help a travelling sales person keep up with their daily mileage driven for business. In your main method, the program should first ask the user how many days of mileage they want to enter and then collect the user input for each day's miles, storing the values entered in an appropriately sized array.

After collecting the user input for the miles, the main method should use a do…while loop to present a menu to the user as shown in the example below. The main method should take the user's pick from the menu and use a switch statement to call the appropriate method(s) to carry out the requested task and output any returned data to the user. The menu should keep being presented to the user until the Exit option is chosen by the user. If the user types in a wrong menu item number, they should be told they entered an invalid choice and then given another chance to choose an option.

User Menu Example:

  1. 1. Find the number of days with 0 miles driven.
  2. 2. Find the day(s) with the highest number of miles driven.
  3. 3. Find the average miles driven.
  4. 4. Print the miles entered by day.
  5. 5. Exit

Choose an option from the menu:

In your class, you should also create the following methods to carry out certain tasks (menu items) for the user.

  • The findZero method will accept the array through a parameter and then return the number of days no miles were driven for business.
  • The findMaxDay method will accept the array through a parameter and then return the day number(s) with the highest number of miles driven. The method should return an int array that contains all of the days with the highest number of miles driven in the case of a tie. Note, the int array should contain the day number the user would recognize as opposed to the index position. For example, the user would expect to see the first day entered as day 1..
  • The calculateAvg method will accept the array through a parameter and then return the average miles driven.
  • The printMiles method will accept the array through a parameter and then print to the console the miles driven each day. Make sure all days are properly labeled, and it is easy to see each day's corresponding miles driven. This method doesn't return any data to the caller, and it should only have to be called one time to print the miles for all the days.

Requirements:

  • All input and output for this program should be done through a Scanner object and the console.
Copyright © 2009-2023 UrgentHomework.com, All right reserved.