I need to write a test using assertEquals to see how many of each coins will be returned to me when money is given and am not sure how to structure it or what info to include. Money can be inserted in the amounts of $1, $2, $5 and $10. Change returned must be in the fewest amount of coins possible.
import java.math.BigDecimal;
public class MakeChange {
BigDecimal numOfQuarters = new BigDecimal(0.00);
BigDecimal numOfDimes = new BigDecimal(0.00);
BigDecimal numOfNickels = new BigDecimal(0.00);
BigDecimal quarter = new BigDecimal(0.25);
BigDecimal dime = new BigDecimal(0.10);
BigDecimal nickel = new BigDecimal(0.05);
public MakeChange() {
}
public String changeAmount(BigDecimal amtToReturn) {
while (amtToReturn.compareTo(quarter) >= 0) {
numOfQuarters = amtToReturn.divideToIntegralValue(quarter);
amtToReturn = amtToReturn.subtract(numOfQuarters.multiply(quarter));
}
while (amtToReturn.compareTo(dime) >= 0) {
numOfDimes = amtToReturn.divideToIntegralValue(dime);
amtToReturn = amtToReturn.subtract(numOfDimes.multiply(dime));
}
while (amtToReturn.compareTo(nickel) >= 0) {
numOfNickels = amtToReturn.divideToIntegralValue(nickel);
amtToReturn = amtToReturn.subtract(numOfNickels.multiply(nickel));
}
return "You will receive: " + numOfQuarters + " Quarters " + numOfDimes + " Dimes and " + numOfNickels
+ " Nickels.";
}
}