Class CorrectChange

java.lang.Object
  extended by CorrectChange

public class CorrectChange
extends Object

CS230 Homework 1

Author:
CS230 staff Purpose: CorrectChange makes change using the fewest number of bills/coins for a specified amount of money without using loops.

Constructor Summary
CorrectChange()
           
 
Method Summary
static void main(String[] args)
           
static int makeChangeWithOneDenomination(int total, String denominationName, int denomination)
          Computes how many occurrences of the specified denomination ("denomination") should be used when making change for the specified amount of cents ("total").
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CorrectChange

public CorrectChange()
Method Detail

makeChangeWithOneDenomination

public static int makeChangeWithOneDenomination(int total,
                                                String denominationName,
                                                int denomination)
Computes how many occurrences of the specified denomination ("denomination") should be used when making change for the specified amount of cents ("total"). The number of occurrences together with the name of the denomination are printed out by the method. The method returns the remaining of amount of cents that we still need to make change for.

For example:

makeChangeWithOneDenomination(57, "quarters", 25) would print out "2 quarters" and return 7 since two quarters should be used when making change for 57 cents and since 7 cents will remain after using the two quarters

makeChangeWithOneDenomination(14, "dimes", 10) would print out "1 dimes" and return 4 since one dime should be used when making change for 14 cents and since 4 cents will remain after using the one dime

makeChangeWithOneDenomination(1743, "$5 bills", 500) would print out "3 $5 bills" and return 243 since 3 $5 bills should be used when making change for 1743 cents and since 243 cents will remain after using the 3 $5 bills

makeChangeWithOneDenomination(1743, "$20 bills", 2000) would print out nothing and return 1743 since no $20 bills should be used when making change for 1743 cents and since 1743 cents will remain after using no $20 bills

Parameters:
total - represents the amount of money in cents that we want to make change for
denominationName - represents the name of the bill or coins, e.g., "$5 bills"
denomination - represents the amount of cents in a particular bill or coin, e.g., 500 (for $5 bills)
Returns:
the remaining of amount of cents that we still need to make change for

main

public static void main(String[] args)