Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Your main method should handle all user input and output to the screen. The actual calculation of change should be performed by a new

1. Your main method should handle all user input and output to the screen. The actual calculation of change should be performed by a new method called makeChange which takes in an amount as a double and returns a description of the resulting change as a String.

If you don't have functional code Lab 2 to start with, you can use this simplified version instead:

package var_and_op; import java.util.Scanner; /** * * @author shohreh */ public class Task2 { public static void main(String[] args) { /*declare all necessary variables */ Scanner input = new Scanner(System.in); double money; int cents; int dollar, quarters , dimes, nickels , pennies; int remainder; /* initialize */ System.out.println("How much money do you have?"); money = input.nextDouble(); /* calculate the change */ cents = (int)(money*100); dollar = cents / 100; remainder = cents % 100; quarters = remainder / 25; remainder = remainder % 25; dimes = remainder/ 10; remainder = remainder% 10; nickels = remainder/ 5; pennies = remainder % 5; /* This will output the different monetary units from the initial user money input. */ System.out.printf("You asked to change $%,.2f dollars ", money); System.out.printf("Your change is: "); System.out.print(dollar +" dollars "); System.out.print(quarters + " quarters "); System.out.print(dimes+" dimes "); System.out.print(nickels+" nickels "); System.out.print(pennies +" pennies "); }// end of main }// end of class Task2

2. Add a comment for your makeChange method. The comment should minimally include descriptions of the method's purpose, its input parameter, and it's return value.

3. Add static variables to keep track of the total number of each kind of coin your change machine has in stock. For example, if your change machine returns dimes and pennies, add a static int dimes and a static int pennies to your code.

4. Add a restock method that sets the static coin counts to reasonable starting amounts, and use it from your main method to initialize them. The restockmethod should not need any input parameters or a return value.

5. Add JavaDoc comments for each of your static variables and the restockmethod.

6. Modify your makeChange code to decrement the coin stock counts by however many coins it uses. For example, if the method returns "2 dimes, and 3 pennies", it should decrement your dimes variable by 2, and your pennies variable by 3. If there are no longer enough coins available in the stock to make change, makeChange should return an error message instead of the change amounts. For example, if you run out of dimes, the method might return "Not enough dimes to make change."

7. Update the comments for your change method to make note of the changed behaviour.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Prove: IfA NP n PSPACE-Complete, then NPC = PSPACE-Complete

Answered: 1 week ago

Question

=+applying to all or most employers and employees?

Answered: 1 week ago

Question

=+associated with political parties and if so, which ones? Are

Answered: 1 week ago