# Remainder - Coins

• 11-13-2012, 05:15 AM
Choustonator
Remainder - Coins
I am creating a program that will take a sum(ex/ \$1.71) and split it up into the least amount of coins.. Where I am stuck is how do I create the part to determine which coins to use. I am trying the remainder where it will see how many of each coin.. But where I am stuck is how do I write it out?

Like this?

sum % 1= pennies;
Then how would I get the new value of sum so I could continue on with nickels, dimes.. etc.

And my last questions is do I need to change my 1.71 to 171 so I can use divide by 100(dollars) 25(quarter) 10(dime) 5(nickel) 1(penny)

Here is my code if you wanted to see. For my assignment I need to create 2 classes.
Code:

```public class USCurrency {                 int dollars, quarters, dimes, nickels, pennies;         double sum = dollars*1 + quarters*.25 + dimes*.1 + nickels*.05 + pennies*.01;                 USCurrency(int nDollars, int nQuarters, int nDimes, int nNickels, int nPennies) {                 sum % 5 = pennies;                         }                         public int getDollars(){                 return dollars;         }                 public int getQuarters(){                 return quarters;         }         public int getDimes(){                 return dimes;         }         public int getNickels(){                 return nickels;                         }         public int getPennies(){                 return pennies;         }         public USCurrency sum (USCurrency a){                 int sumDollars, sumQuarters, sumDimes, sumNickels, sumPennies;                 sumDollars = this.dollars + a.getDollars();                 sumQuarters = this.quarters + a.getQuarters();                 sumDimes = this.dimes + a.getDimes();                 sumNickels = this.nickels + a.getNickels();                 sumPennies = this.pennies + a.getPennies();                 return new USCurrency(sumDollars,sumQuarters,sumDimes,sumNickels,sumPennies);                         }                         }```

Code:

```public class TestUSCurrency {         public static void main(String[] args){                 USCurrency jen = new USCurrency(1,0,0,0,141);                 USCurrency bob = new USCurrency(0,4,3,2,1);                 USCurrency total = jen.sum(bob);                 System.out.[U][COLOR="#FF0000"]print[/COLOR][/U](jen.getDollars(), jen.getQuarters(), jen.getDimes(), jen.getNickels(), jen.getPennies());                 } }```
I also have an error right there for the 'print'. But I dont know why.
• 11-13-2012, 05:15 PM