Hey guys, could use some help on this program that I'm making.
I'm working on a change dispensing program using a constructor, getters, setters, and a couple of different methods.
So basically, this program takes a constructures that assumes that a change machine has been loaded with a roll of each type of coin. When it goes below 1 of that type of coin it adds another roll and records how many rolls it has added. It also reduces the penniesLeft, nickelsLeft, dimesLeft, and quartersLeft by how many of those coins are needed to make the amount of change. So when they go below 1 it adds a roll of change, I'm missing a writeReport() method which I should right it to System.out. I'm missing the constructor and my make change method that reduces the pennies left and calculates how many of each type is needed to make the correct change using as few coins is also messed up.
I'm really lost at this point and am looking for some help, any would be appreciated, thank you.
--- Update ---
Here's what I want it to look like, http://i.imgur.com/1aemCiV.png
--- Update ---
Here's my codeHere's my change driver,package changedispenser; public class ChangeDispenser { private static int quarters, dimes, nickels, pennies; private static int penniesLeft, nickelsLeft, dimesLeft, quartersLeft; private static int pennyRollsAdded = 1; private static int nickelRollsAdded = 1; private static int dimeRollsAdded = 1; private static int quarterRollsAdded = 1; public static final int PENNIES_PER_ROLL = 50; public static final int NICKELS_PER_ROLL = 40; public static final int DIMES_PER_ROLL = 50; public static final int QUARTERS_PER_ROLL = 40; public static void main(String[] args) { public String makeChange(int amount) { if (amount > 99 || amount < 0) { System.out.println(""); } quarters = amount / 25; amount = amount % 25; dimes = amount / 10; amount = amount % 10; nickels = amount / 5; amount = amount % 5; pennies = amount; do { if (quarters != 0) { System.out.print(" Quarters: " + quarters); } if (dimes != 0) { System.out.print(" Dimes: " + dimes); } if (nickels != 0) { System.out.print(" Nickels: " + nickels); } if (pennies != 0) { System.out.println(" Pennies: " + pennies); } //Fix this so that it outputs the appropriate change IE: 23 cents is 2 dimes 3 pennies System.out.println("Coins Left:"); System.out.println("Quarters: " + quartersLeft); System.out.println("Dimes: " + dimesLeft); System.out.println("Nickels: " + nickelsLeft); System.out.println("Pennies: " + penniesLeft); System.out.println("Rolls Added: "); System.out.println("Quarters: " + quarterRollsAdded); System.out.println("Dimes: " + dimeRollsAdded); System.out.println("Nickels: " + nickelRollsAdded); System.out.println("Pennies: " + pennyRollsAdded); } while (amount > 0 && amount <= 99); return "Quarters: " + quarters + " Dime: " + dimes + " Nickels: " + nickels + " Pennies: " + pennies; } public int getPenniesLeft() { return penniesLeft; } public void setPenniesLeft(int penniesLeft) { this.penniesLeft = penniesLeft; if (penniesLeft <= 0) { pennyRollsAdded = pennyRollsAdded++; } } public int getNickelsLeft() { return nickelsLeft; } public void setNickelsLeft(int nickelsLeft) { this.nickelsLeft = nickelsLeft; if (nickelsLeft <= 0) { nickelRollsAdded = nickelRollsAdded++; } } public int getDimesLeft() { return dimesLeft; } public void setDimesLeft(int dimesLeft) { this.dimesLeft = dimesLeft; if (dimesLeft <= 0) { dimeRollsAdded = dimeRollsAdded++; } } public int getQuartersLeft() { return quartersLeft; } public void setQuartersLeft(int quartersLeft) { this.quartersLeft = quartersLeft; if (quartersLeft <= 0) { quarterRollsAdded = quarterRollsAdded++; } } public int getPennyRollsAdded() { return pennyRollsAdded; } public void setPennyRollsAdded(int pennyRollsAdded) { this.pennyRollsAdded = pennyRollsAdded; } public int getNickelRollsAdded() { return nickelRollsAdded; } public void setNickelRollsAdded(int nickelRollsAdded) { this.nickelRollsAdded = nickelRollsAdded; } public int getDimeRollsAdded() { return dimeRollsAdded; } public void setDimeRollsAdded(int dimeRollsAdded) { this.dimeRollsAdded = dimeRollsAdded; } public int getQuarterRollsAdded() { return quarterRollsAdded; } public void setQuarterRollsAdded(int quarterRollsAdded) { this.quarterRollsAdded = quarterRollsAdded; } }
package changedispenser; import java.util.Random; public class ChangeDispenserDriver { public static void main(String[] args) { ChangeDispenser changeMachine = new ChangeDispenser(); Random rand = new Random(); int amount; for (int i = 0; i < 1000; i++) { amount = rand.nextInt(99) + 1; System.out.println("Amount: " + amount + ": Change = " + changeMachine.makeChange(amount)); } changeMachine.writeReport(); } }