Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/menudrivenprogram-java/
- Background information
- For this exercise you are to complete the implementation of two options in a menu-driven Java console application. The menu part of the program has been written and you will use this code to implement the two options, which are to
- • Investment Report
- • Rainfall Report
- The third option is implemented and causes the program to exit/terminate.
- The partially completed program is syntactically correct and you should study the code and then compile and execute it before you start work on implementing the two new options – this will allow you to better understand the flow of execution of the program, as is.
- Details
- Requirement A – Investment Report :
- The program should prompt for and accept three values from the user:
- • the initial deposit amount (a double value representing the deposit value in dollars)
- • the rate of interest earned per annum (yearly) on the account balance (a double value representing the actual interest rate percentage, for example, 6.0% would be entered as 6.0)
- • the amount that is to be deposited to the account each month (assume the deposit amount for each month is the same).
- Once the user has supplied the initial deposit amount and interest rate for the account as well as the monthly deposit amount, the program should then proceed to calculate the new balance for the account (including interest earned) over a six month period (taking into account the additional amount being deposited and the interest earned for each month).
- This should be done without using loops of any kind, as the emphasis is on using variables to help break down a repetitive process into here.
- A simple way of handling the calculation of the balance for each month of the investment period is shown below:
- balance = balance + monthly deposit amount
- interest = balance (current) * ((interest rate / 12) / 100)
- balance (new) = balance (current) + interest
- Note that the interest rate is per annum (across the entire year), so the interest rate percentage for each month is equivalent to the yearly interest rate divided by 12.
- Your program should display the interest earned and the value of the investment for each month of the 6-month period in a table similar to that shown in the screen shot shown below.
- Note that the values used in this screenshot are for example purposes only – the user may enter values different to those shown, which would make the results that would be generated different to those displayed.
- Requirement B – Rainfall Report :
- This menu option is to be implemented with little help from us, so you need to actively discuss the requirements in the forum where we will answer your queries!
- For this option your program should prompt the user to enter 7 separate daily rainfall measures in millimetres and then report the average daily rainfall (in centimetres) and the standard deviation of the measures entered, using the computed (centimetre) average.
- The report must be presented with the first row presenting the day numbers, properly spaced out, the second row presenting the rainfall measures in centimetres to two decimal places of accuracy, and the final row presenting the average and standard deviation, to two and four decimal places of accuracy, respectively.
- Requirement C – Program Menu :
- For this part you are required to comment the part of the code responsible for displaying the menu and processing the user’s selections. No detailed explanation has provided for the menu code so you will need to do so yourself.
- Your task is to demonstrate your understanding of repetition and selection by providing comments which explain to the reader what the significant code segments and control structures in the menu code do in the program.
- Menu code below:
- import java.util.Scanner;
- public class MenuDrivenProgram
- {
- private static Scanner s = new Scanner(System.in);
- public static void main(String[] args)
- {
- String inputLine;
- char option = ‘ ‘;
- do
- {
- printMenu();
- System.out.printf(“Please select a valid option: “);
- inputLine = s.nextLine();
- if (inputLine.length() != 1)
- {
- System.out.printf(“Error! You did not select a valid option!\n”);
- System.out.printf(“Please try again\n\n”);
- }
- else
- {
- option = inputLine.charAt(0);
- option = Character.toUpperCase(option);
- switch (option)
- {
- case ‘A’:
- InvestmentReport();
- break;
- case ‘B’:
- RainfallReport();
- break;
- case ‘X’:
- System.out.printf(“Exiting the program – goodbye…\n\n”);
- break;
- default:
- System.out.printf(“Error!” +
- “\”%c\” is not a valid menu option!\n\n”,
- option);
- }
- }
- } while (option != ‘X’);
- }
- public static void printMenu()
- {
- System.out.printf(“********************** Menu *********************\n\n”);
- System.out.printf(“\tA. InvestmentReport.\n”);
- System.out.printf(“\tB. RainfallReport.\n”);
- System.out.printf(“\tX. Exit the program\n\n”);
- System.out.printf(“*************************************************\n\n”);
- }
- public static void InvestmentReport()
- {
- System.out.printf(“*** Investment Report stub ***\n”);
- // This is where your Part A solution goes
- }
- public static void RainfallReport()
- {
- System.out.printf(“*** Rainfall Report stub ***\n”);
- // This is where your Part B solution goes
- }
- }
- Download: http://solutionzip.com/downloads/menudrivenprogram-java/
Advertisement
Add Comment
Please, Sign In to add comment