Question: Write a program, called Bank , that will do the following: Declare an integer array of size 12 with each slot having the value 0.

Write a program, called Bank, that will do the following:

Declare an integer array of size 12 with each slot having the value 0. Each slot will represent the quantity of each denomination currently in the bank. The denominations are penny, nickel, dime, quarter, half-dollar, dollar coin, one dollar bill, five dollar bill, ten dollar bill, twenty dollar bill, fifty dollar bill, and one hundred dollar bill.

Declare a double array of size 12 with each slot containing the corresponding value of each denomination (.01, .05, .1, .25, .5, 1, 1, 5, 10, 20, 50, 100)

Welcome the user to the Piggy Bank application

Display a main menu as follows:

0-Exit

1-Add money to bank

2-Remove money from bank

3-Show quantity of each denomination

4-Show total value in bank

Enter your choice:

The actions for each menu choice are given below

User selects 1-Add money to bank:

The program repeatedly prompts the user to add money using the following menu:

0-Quit adding money

1-Add a penny

2-Add a nickel

3-Add a dime

4-Add a quarter

5-Add a half-dollar

6-Add a dollar coin

7-Add a 1 dollar bill

8-Add a 5 dollar bill

9-Add a 10 dollar bill

10-Add a 20 dollar bill

11-Add a 50 dollar bill

12-Add a 100 dollar bill

Enter your choice:

With each valid selection, other than 0, the appropriate slot will be incremented by 1, and the menu is displayed again, waiting for the next selection. (Dont forget that arrays begin with index 0!)

When a 0 is selected from this menu, the program should revert back to the main menu.

When an invalid selection is made, an invalid message is displayed and the add menu is displayed again.

User selects 2-Remove money from bank:

The program repeatedly prompts the user to remove money using the following menu:

0-Quit removing money

1-Remove a penny

2-Remove a nickel

3-Remove a dime

4-Remove a quarter

5-Remove a half-dollar

6-Remove a dollar coin

7-Remove a 1 dollar bill

8-Remove a 5 dollar bill

9-Remove a 10 dollar bill

10-Remove a 20 dollar bill

11-Remove a 50 dollar bill

12-Remove a 100 dollar bill

Enter your choice:

With each valid selection, other than 0, the appropriate slot will be decremented by 1 if there is a positive value stored there, and the menu is displayed again, waiting for the next selection. An error message should be displayed if the original value in the slot is 0, because no denomination exists, and no changes to the array should be made.

When a 0 is selected from this menu, the program should revert back to the main menu.

When an invalid selection is made, an invalid message displays and the remove menu is displayed again.

User selects 3-Show quantity of each denomination:

The program should display each denomination and how many of that denomination are currently in the bank.

For example one output might be,

$0.01 4

$0.05 342

$0.10 23

$0.25 593

$0.50 49

$1.00 3

$1.00 32

$5.00 84

$10.00 91

$20.00 5

$50.00 1

$100.00 - 7

Then the program should display the main menu again.

User selects 4- Show total value in bank:

The program should display, in dollar format, the total value of the items currently in the bank.

For example one output might be,

The total amount in the bank is $2,392.49

Then the program should display the main menu again.

User selects 0-Exit

The program should display a goodbye message, and the program should naturally end.

User selects an invalid number

The program should display an invalid message, and the program should display the main menu.

It is wise to break the problem down into smaller, manageable pieces using methods. In an effort to show this functional decomposition, I am supplying a skeleton of the program below. Copy and paste this into the program you create in NetBeans and then complete the missing code at the appropriate comments.

Make sure you test you program thoroughly. Think of the extreme cases and test for those.

Make sure you have ample meaningful comments for the code segments you wrote.

Remove any unnecessary white space and format your program using Source/Format before submitting.

/*This is our own work: List team member names here

10/26/2016

This program simulates a piggy bank, allowing the user to add items to the bank, remove items from the bank, show the quantity of each denomination currently in the bank, and showing the total value currently in the bank.*/

import java.util.Scanner;

public class Bank {

public static void main(String[] args) {

//declare an integer array of size 12 called bank. Set all slots to zero.

/*declare a real number array of size 12, called denom, and initialize it with the appropriate denomination values from smallest to largest denomination*/

int mainChoice, addChoice, removeChoice;

Scanner kb = new Scanner(System.in);

//write the welcome message here

do {

//call the displayMainMenu method here

mainChoice = kb.nextInt();

switch (mainChoice) {

case 0:

System.out.println("Goodbye!");

break;

case 1:

do {

//call the displayAddMenu method here

addChoice = kb.nextInt();

/*add statements here to handle invalid choices, valid choices, and a choice of zero. Consider using if/else statements here.*/

} while (addChoice != 0);

break;

case 2:

do {

//call the displayRemoveMenu here

removeChoice = kb.nextInt();

/*add statements here to handle invalid choices, valid choices, valid choices where there are no items of that denomination, and a choice of zero. Consider using if/else statements here.*/

} while (removeChoice != 0);

break;

case 3:

/*call showDenoms method (make sure to pass it both arrays with the bank array being the first argument*/

break;

case 4:

/*call showTotal method (make sure to pass it both arrays with the bank array being the first argument*/

break;

default:

System.out.println("Invalid choice. Try again. ");

}

} while (mainChoice != 0);

}

public static void displayMainMenu() {

System.out.print("0 - Exit "

+ "1 - Add money to bank "

+ "2 - Remove money from brank "

+ "3 - Show quantity of each denomination "

+ "4 - Show total value in bank "

+ "Enter your choice: ");

}

public static void displayAddMenu() {

System.out.print("0-Quit adding money "

+ "1-Add a penny "

+ "2-Add a nickel "

+ "3-Add a dime "

+ "4-Add a quarter "

+ "5-Add a half-dollar "

+ "6-Add a dollar coin "

+ "7-Add a 1 dollar bill "

+ "8-Add a 5 dollar bill "

+ "9-Add a 10 dollar bill "

+ "10-Add a 20 dollar bill "

+ "11-Add a 50 dollar bill "

+ "12-Add a 100 dollar bill "

+ "Enter your choice: ");

}

public static void displayRemoveMenu() {

System.out.print("0-Quit removing money "

+ "1-Remove a penny "

+ "2-Remove a nickel "

+ "3-Remove a dime "

+ "4-Remove a quarter "

+ "5-Remove a half-dollar "

+ "6-Remove a dollar coin "

+ "7-Remove a 1 dollar bill "

+ "8-Remove a 5 dollar bill "

+ "9-Remove a 10 dollar bill "

+ "10-Remove a 20 dollar bill "

+ "11-Remove a 50 dollar bill "

+ "12-Remove a 100 dollar bill "

+ "Enter your choice: ");

}

/*write the showDenoms method here. This method should accept an integer array followed by a double array. It should show a table of each denomination followed by how many items of that denomination are in the bank. It should not return anything.*/

/*write the showTotal method here. This method should accept an integer array followed by a double array. If should calculation the total value in the bank and display that result. It should not return anything.*/

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!