Instruction
These are the instructions for your third programming project. Recall that all code must be written individually and independently. Recall that violating this rule will result in zero credit for the project and probably a failing grade in the course.
Problem:
Develop a recursive method to determine the number of distinct ways in which a given amount of money in cents can be changed into quarters, dimes, nickels, and pennies. Each line of input contains an amount. For example, if the amount is 17 cents, then there are six ways to make change:
1 dime, 1 nickel, and 2 pennies
1 dime, and 7 pennies
3 nickels and 2 pennies
2 nickels and 7 pennies
1 nickel and 12 pennies
17 pennies
The method specification is
public static int ways(int amount, int denomination)
For the value of denomination, 1 - penny, coins 2- nickel, 3 - dime and 4 - quarter. The running result example is
Input the amount between 1 and 99: 17
There are 0 quarter, 1 dime, 1 nickel, 2 penny
There are 0 quarter, 1 dime, 0 nickel, 7 penny
There are 0 quarter, 0 dime, 3 nickel, 2 penny
There are 0 quarter, 0 dime, 2 nickel, 7 penny
There are 0 quarter, 0 dime, 1 nickel, 12 penny
There are 0 quarter, 0 dime, 0 nickel, 17 penny
There are totally 6 ways.
Here are some input/output pairs. The first number in each pair is the amount, and the second number is the number of ways in which the amount can be changed into quarters, dimes, nickels, and pennies:
17 6
5 2
10 4
25 13
42 31
61 73
99 213
Test your methods ways method with a main method that reads in an integer amount in cents between 1 and 99, inclusive, and outputs the total number of ways that amount can be changed into quarters, dimes, nickels, and pennies, and each way in detail.
Hint: Let us simplify the problem as follows:
Given a positive integer n, how many ways can we make change for n cents using pennies, nickels, dimes and quarters?
Recursively, we could break down the problem as follows:
To make change for n cents we could:
1) Give the customer a quarter. Then we have to make change for n-25 cents
2) Give the customer a dime. Then we have to make change for n-10 cents
3) Give the customer a nickel. Then we have to make change for n-5 cents
4) Give the customer a penny. Then we have to make change for n-1 cents.
What to hand in?
• A report includes problem statement, analysis, algorithm design, class prototype (class contract), program Input/Output, and tested results (analysis your result to see if it is correct).
• You code should return the error message with invalid input such as negative numbers, or the destination’s value is smaller than the origin’s.
• The source program (name your file “project3.java”)
• You could either submit through Blackboard or my email box.
Each Java program should have the following in the beginning:
// Program Name:
// Programmer: ,
// Assignment Number:
// Purpose: