Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class VendingMachine {
  4. Scanner in = new Scanner(System.in);
  5. double price;
  6. double bill;
  7.  
  8. double change;
  9. int numberOfDollarCoins;
  10. int numberOfQuarterCoins;
  11. double quarter = 0.25;
  12.  
  13. void inputMoney() {
  14. System.out.print("What item do you want? (Price) ");
  15. price = in.nextDouble();
  16.  
  17. System.out.print("How much are you putting in? ");
  18. bill = in.nextDouble();
  19. }
  20.  
  21. void difference () {
  22. price = price * 100;
  23. bill = bill * 100;
  24. change = bill - price;
  25. }
  26.  
  27. void typeOfCoinsForChange () {
  28. numberOfDollarCoins = (int)change / 100;
  29. numberOfQuarterCoins = (int)((change - numberOfDollarCoins*100) / (quarter * 100));
  30. }
  31. public static void main(String[] args) {
  32. VendingMachine one = new VendingMachine();
  33.  
  34. one.inputMoney();
  35. one.difference();
  36. one.typeOfCoinsForChange();
  37. System.out.println("Dollar Coins: " + one.numberOfDollarCoins);
  38. System.out.println("Quarter Coins: " + one.numberOfQuarterCoins);
  39. //System.out.println("Your change is " + one.numberOfDollarCoins + " dollars and " + one.numberOfQuarterCoins
  40. // + " quarters.");
  41. }
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement