Original Post
HEllo, im having trouble with a part that should probably be pretty simple.
The program should take the users input, then output the amount in change is left over, and how many of each coin will be dispensed as change (cannot output dollors, if its a dollor it should be represented as 4 quarters)
Here is my code thus far:
[Edited by - Zahlman on November 24, 2010 7:04:17 AM]
The program should take the users input, then output the amount in change is left over, and how many of each coin will be dispensed as change (cannot output dollors, if its a dollor it should be represented as 4 quarters)
Here is my code thus far:
import java.util.*; import java.io.*; public class VendMach { public static void main(String [] args) { int chooseProduct; int moneyInput; int calculateChange; } public static void chooseProduct() { Scanner scanner = new Scanner(System.in); System.out.println(""); System.out.println("Please enter your choice - 100: Coke, 110: Diet Coke, 120: Sprite, 130: Diet Sprite, 140: Milk, 150: Water "); System.out.print("Your choice: "); Global.choice = scanner.nextInt(); switch(Global.choice){ case 100: case 110: Global.price = 1.25; break; case 120: case 130: Global.price = 1.75; break; case 140: Global.price = 1.15; break; case 150: Global.price = 0.55; break; default: System.out.println("Please try again."); chooseProduct(); } } public static void moneyInput() { Scanner scanner = new Scanner(System.in); System.out.println("Please deposit money:"); System.out.print("Number of $1.00 bils: "); Global.numDollar = scanner.nextInt(); System.out.print("Number of Quarters: "); Global.numQuart = scanner.nextInt(); System.out.print("Number of Dimes: "); Global.numDimes = scanner.nextInt(); System.out.print("Number of Nickels: "); Global.numNickel = scanner.nextInt(); } public static void calculateChange() { double change = (((Global.numDollar * Global.Dollar) + (Global.numQuart * Global.Quart) + (Global.numDimes * Global.Dimes) + (Global.numNickel * Global.Nickel)) - Global.price); System.out.println("Your change is: $" + change); int amount = (int) (100 * (change - Global.price)); Global.numQuart = amount /25; amount -= Global.numQuart * 25; Global.numDimes = amount / 10; amount -= Global.numDimes * 10; Global.numNickel = amount / 5; System.out.println("Please recieve " + Global.numQuart + " quarters " + Global.numDimes + " Dimes " + Global.numNickel + " Nickels."); if (Global.choice == 100) { System.out.println("Your Coke is vending."); } else if (Global.choice == 110) { System.out.println("Your Diet Coke is vending."); } else if (Global.choice == 120) { System.out.println("Your Sprite is vending."); } else if (Global.choice == 130) { System.out.println("Your Diet Sprite is vending."); } else if (Global.choice == 140) { System.out.println("Your Milk is vending."); } else if (Global.choice == 150) { System.out.println("Your Water is vending."); } else { } } }//----- end of methods program/main program//-------- this is the program that calls on these methods public class vendTes { public static void main(String [] args) { VendMach mach1 = new VendMach(); mach1.chooseProduct(); mach1.moneyInput(); mach1.calculateChange(); } }[Edited by - Zahlman on November 24, 2010 7:04:17 AM]