ZhenghaoZhu

McDonaldsProject

Dec 30th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class McDonaldsProject{
  4. public static void main(String[] args){
  5. Scanner input = new Scanner(System.in);
  6. System.out.println("Enter your amount.");
  7. int bill = input.nextInt();
  8. if (bill >= 100)
  9. System.out.println("Sorry we dont accept 100 or more");
  10. int twenty = bill/20;
  11. int billTemp = bill - (twenty * 20);
  12. int ten = billTemp/10;
  13. bill = bill - (ten * 10);
  14. int five = billTemp/5;
  15. bill = bill - (five * 5);
  16. int ones = billTemp/1;
  17. bill = bill - (ones * 1);
  18.  
  19. if(twenty > 0) //Do we need 20's?
  20. System.out.print(twenty + " Twenties ");
  21. if(ten > 0)
  22. System.out.print(ten + " Tens ");
  23. if(five > 0)
  24. System.out.print(five + " Fives ");
  25. if(ones >0)
  26. System.out.print(ones + " Ones ");
  27. if(bill==0)
  28. System.out.println("You need no change.");
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment