Question

For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project...

For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project 02). The zip file contains a P02.java, a HelperClass.java, and an enumeration under Money.java. The only coding you’ll do will be in P02.java. I’ve already provided you with the menu and switch as well as all the methods you’ll need stubbed out. Your assignment is to take the program and complete it without adding any more methods but merely adding code to those stubbed out methods. I’ve coded the switch statement that will call those methods. You only need to put code in these methods for add, remove, view, and empty.

You will use the helper class to get all input from the user. If an int is needed use HelperClass.getIntegerInput(prompt) If a double is then use HelperClass.getIDoubleInput(prompt) If a String is required use HelperClass.getStringInput(prompt), and so on.

Menu Choice 1: When menu choice 1 is selected you will display all possible denominations with the numerical values in a list and ask the user what numerical value they would like to put in the wallet (-1 to exit back to the main menu).

Ask them to enter the amount and you will check if they entered -1 which will exit back to the main menu. If they didn’t enter -1 then check against the enumeration Money to see if that is a valid amount. If it is a valid amount then add that amount to the Vector of doubles simulating putting the money in the virtual wallet.

You will keep prompting them to put money in the wallet until they enter a -1. I suggest using a do while until -1 is entered. Remember that the user will be entering a double so check for -1.0 in your do while.

Menu Choice 2: Remove money from wallet. When this option is selected you will display all the money in the wallet and ask the user to enter a numerical amount for a value in the wallet. You can group the amounts and even sort them if you like. I suggest you code displayMoneyInWallet() first and call this from this method to show the user what they have in the wallet. Allow the user to keep removing money until either the wallet is empty or -1 is entered. Each time they enter something show them what’s in the wallet again and ask them to enter another amount or -1.

Each time you will check against the enumeration to first make sure it’s a valid amount. If it is then you will check the vector (wallet) to make sure it is in there, removing the first instance of that value.

Menu Choice 3: Display Money in Wallet. When display money is selected display the contents of the wallet to the screen. The output doesn’t need to be sorted but it does need to be grouped. Sorting would be cool though. Just display what’s in the wallet with the name of the denomination as well as the total in the wallet. You’ll need to group the denominations. I suggest just creating variables for each denomination, setting it initially to zero, like penny, nickel, dime…. And as you loop through the wallet increment these values displaying only the denominations you have in the wallet.

Output could be something like: 10 Penny 2 Quarter 2 Five 1 Ten Total: $ 20.60 That’s all this method does.

Menu Choice 4: When option 4 is selected from emptyWallet() you will call displayWallet to show the user what was in their wallet and then clear out the Vector (wallet).

Menu Choice 5: When 5 is selected the program exits. I’ve already coded this for you.

THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE SHOULD RUN.

package p02;

import static java.lang.System.*;
import java.io.*;
import java.util.*;

public class P02 {
  
public static Vector<Double> wallet=new Vector<Double>();
  
public static void addMoneyToWallet(){
  
}
  
public static void removeMoneyFromWallet(){
  
}
  
public static void displayMoneyInWallet(){
  
}
  
public static void emptyWallet(){
  
}

  
public static void main(String[] args){
int choice=0;
String menu="Wallet Application:\n\n" +
"1) Add Money to Wallet\n" +
"2) Remove Money from Wallet\n" +
"3) Display Money in Wallet\n" +
"4) Empty Wallet\n" +
"5) Exit\n" +   
"Please enter a selection->";
do {
choice=HelperClass.getIntegerInput(menu);
switch(choice){
case 1:
addMoneyToWallet();
break;
case 2:
removeMoneyFromWallet();
break;
case 3:
displayMoneyInWallet();
break;
case 4:
emptyWallet();
break;
case 5:
out.println("Okay, goodbye!!!");
break;
default:
out.println("That is not a valid choice.../nPlease try again!!!\n\n");
break;
}
}while(choice!=5);   
}
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. addMoneyToWallet()

public static void addMoneyToWallet()

{

Money[] denominations = Money.values();

boolean isValidDenom = false;

while(true)

{

// show all the denominations.

for(Money denomination: denominations)

{

System.out.println(denomination.getDenom());

}

double moneyToBeAdded = HelperClass.getDoubleInput("Select any of these denominations by entering their value or -1 to go back to main menu : ");

isValidDenom = false;

// if the user doesn't select -1

if(moneyToBeAdded != -1.0)

{

for(Money denomination : denominations)

{

if(denomination.getDenom() == moneyToBeAdded)

{

isValidDenom = true;

}

}

// check if it is valid in the first place.

if(isValidDenom)

{

// then add to the wallet.

wallet.add(moneyToBeAdded);

}

else

{

System.out.println("That's not a valid denomination or -1 to exit: ");

continue;

}

}

// return if -1 is entered.

else return;

}

}

removeMoneyFromWallet()

public static void removeMoneyFromWallet()

{

double totalMoney = 0;

for(double money : wallet)

{

totalMoney += money;

}

while(totalMoney != 0)

{

// first display the money in the wallet.

displayMoneyInWallet();

double moneyToBeRemoved = HelperClass.getDoubleInput("Enter any denomination present in your wallet or -1 to go back to main menu: ");

// if the user doesn't select -1.

if(moneyToBeRemoved != -1.0)

{

// remove the money

wallet.remove(moneyToBeRemoved);

totalMoney -= moneyToBeRemoved;

}

else return;

} // give the option to remove until there is no money in the wallet.

}

displayMoneyInWallet()

public static void displayMoneyInWallet()

{

int penny=0;

int nickel= 0;

int dime= 0;

int quarter= 0;

int half= 0;

int one= 0;

int two= 0;

int five= 0;

int ten= 0;

int twenty= 0;

int fifty= 0;

int hundred = 0;

double totalMoney = 0;

// loop through the wallet and count all the denominations.

for(double money: wallet)

{

if(money == .01) penny++;

else if(money == .05) nickel++;

else if(money == .10) dime++;

else if(money == .25) quarter++;

else if(money == .50) half++;

else if(money == 1.00) one++;

else if(money == 2.00) two++;

else if(money == 5.00) five++;

else if(money == 10.00) ten++;

else if(money == 20.00) twenty++;

else if(money == 50.00) fifty++;

else if(money == 100.00) hundred++;

// increment the total money.

totalMoney += money;

}

System.out.println("Money in wallet");

if(penny != 0) System.out.println(penny + " penny");

if(nickel != 0) System.out.println(nickel + " nickel");

if(dime != 0) System.out.println(dime + " dime");

if(quarter != 0) System.out.println(quarter + " quarter");

if(half != 0) System.out.println(half + " half");

if(one != 0) System.out.println(one + " one");

if(two != 0) System.out.println(two + " two");

if(five != 0) System.out.println(five + " five");

if(ten != 0) System.out.println(ten + " ten");

if(fifty != 0) System.out.println(fifty + " fifty");

if(twenty != 0) System.out.println(twenty + " twenty");

if(hundred != 0) System.out.println(hundred + " hundred");

System.out.println("Total : $ " + totalMoney);

}

emptyWallet()

public static void emptyWallet()

{

displayMoneyInWallet();

wallet.clear();

}

Add a comment
Know the answer?
Add Answer to:
For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE...

    THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE SHOULD RUN. FILL IN THE CODE PLEASE. package p02; import static java.lang.System.*; import java.io.*; import java.util.*; public class P02 {    public static Vector<Double> wallet=new Vector<Double>();    public static void addMoneyToWallet(){    }    public static void removeMoneyFromWallet(){    }    public static void displayMoneyInWallet(){    }    public static void emptyWallet(){    }    public static void main(String[] args){ int choice=0; String menu="Wallet...

  • In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class...

    In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files.  One (.h) file for the class definitions, both of them.  The class implementation file which has the member function definitions. And the main project file where your main...

  • I am almost done with this code, but for some reason I am still getting an...

    I am almost done with this code, but for some reason I am still getting an error message: Some of the instructions were: Using a loop, prompt for a currency to find. Inside the loop that manages the input, call the lookUpCurrency() method can pass the inputted currency code value. The lookUpCurrency() method needs to loop through the list of currencies and compare the passed currency code with the code in the array. If found, return true - otherwise return...

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • •create a new savings account object (for choice 2). •ask the user to enter an initial...

    •create a new savings account object (for choice 2). •ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered. •Set the balance of the savings account object by calling the setBalance() method. •Ask the user to deposit an amount. Deposit that amount and display the balance of the...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to...

    Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called Social Security. In simplest terms, it’s a way to pay into a system and receive money back when you retire (and the longer you work and the higher your salary, the higher your monthly benefit). Interestingly,...

  • JAVA Code Requried Copy the file java included below. This program will compile, but, when you...

    JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT