Question
Hello, I would like an expert to help me complete the following exrcise, Please follow the specifications provided. Thanks Operation The application prompts the user
Hello, I would like an expert to help me complete the following exrcise, Please follow the specifications provided. Thanks
Operation
The application prompts the user to enter a number of cents from 0 to 99.
The application displays the minimum number of quarters, dimes, nickels, and pennies that represent the coins that make up the specified number of cents.
The application prompts the user to continue.
Specifications
Assume that the user will enter a valid integer value for the number of cents.
The application should continue only if the user enters y or Y to continue
Instead of using constants or literals as in the text, well use an Enumerated class named Coins.
Well start by making a NetBeans project named Lab2. It will be a project of type Java Application. Set the project location to your thumb drive or somewhere that will not disappear the next time your computer starts. Name the main class MakeChange.
Right click on the Source Packages line and create a new package called my.change. Right click on my.change and create a new Java Enum class called Change. (You may have to select the Other option from the New offerings and click on the Java category to find the Java Enum option.)
Your enum will contain an item for quarters, dimes, nickels and pennies. Make sure to follow constant naming standards. The enum items will have two instance variables: coinName (a String) and coinValue (an int).
Use your IDE to create a constructor that sets both values. Use the IDE to override the toString method and change the code so the method only returns the coinName string. Encapsulate the enum variables so that they have private visibility. Since we want users to access (get) them, but we dont want other classes to mutate (set) the variables, we will provide getters but not setters for the two attributes. (This will be done by the IDE if you right-click in the code, select Refactor, and select Encapsulate fields.) Thats all we need for the enumerated class.
In the MakeChange application main method, we have decided to use stdin (System.in) and stdout (System.out) for input and output. Hence, well make a Scanner object based on System.in. Well also declare three local variables: int val, int coins and String cont.
Well use a post-test (do) loop to get user input and an Object for loop to calculate the coins. Inside the loop we will carry out the following steps:
Use the Scanner object to get the value (assume it will be an int and assume it will be less than 100. Dont worry about Exceptions.)
Create an Object for loop that will print out the
Number of coins of that denomination and
The Coin name (grammatically correct)
Figure out how much is left over
This will all be done using integer division and the modulus (%) operator
Prompt the user to see if she or he wants to go again. If the first character of the String that the user enters is Y, do it again.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started