You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
801 B
28 lines
801 B
//We took the code that deals with coinCounts and moved it into this class. The weight variable is eliminated too. This is better design.
|
|
|
|
public class CoinInventory {
|
|
private int[] coinCounts; //cp (pennies), sp (dimes), ep (half-dollars), gp (dollar bills), pp (five dollar bills)
|
|
|
|
public CoinInventory() {
|
|
coinCounts = new int[5];
|
|
}
|
|
|
|
public void collectMoney(int cp, int sp, int ep, int gp, int pp) {
|
|
coinCounts[0] += cp;
|
|
coinCounts[1] += sp;
|
|
coinCounts[2] += ep;
|
|
coinCounts[3] += gp;
|
|
coinCounts[4] += pp;
|
|
}
|
|
|
|
public double getMoneyValue() {
|
|
return .01 * coinCounts[0] + .1 * coinCounts[1] + .5 * coinCounts[2] + 1 * coinCounts[3] + 5 * coinCounts[4];
|
|
}
|
|
|
|
public int getWeight() {
|
|
return coinCounts[0] + coinCounts[1] + coinCounts[2] + coinCounts[3] + coinCounts[4];
|
|
}
|
|
|
|
|
|
}
|