GameNCode

Roy & Omri Efficient Money Calculator

Dec 24th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. /**
  2. * Created by Roy & Omri on 12/24/2015.
  3. */
  4.  
  5. import java.util.Scanner;
  6. public class Money {
  7. public static void main(String []args){
  8. Scanner UI = new Scanner(System.in);
  9. System.out.println("How much money do you have?");
  10. int money = UI.nextInt();
  11. int result = 0;
  12. int twohundredBill = 0;
  13. int hundredBill = 0;
  14. int fiftyBill = 0;
  15. int twentyBill = 0;
  16. int tenCoin = 0;
  17. int fiveCoin = 0;
  18. int twoCoin = 0;
  19. int oneCoin = 0;
  20. while(money > 0){
  21. if(money < 200){
  22.  
  23. if(money < 100){
  24.  
  25. if(money < 50){
  26.  
  27. if(money < 20){
  28.  
  29. if(money < 10){
  30.  
  31. if(money < 5){
  32.  
  33. if(money < 2){
  34.  
  35. money -= 1;
  36. oneCoin += 1;
  37. }
  38. else {
  39. money -= 2;
  40. twoCoin += 1;
  41. }
  42. }
  43. else {
  44. money -= 5;
  45. fiveCoin += 1;
  46. }
  47. }
  48. else {
  49. money -= 10;
  50. tenCoin += 1;
  51. }
  52. }
  53. else{
  54.  
  55. money -= 20;
  56. twentyBill += 1;
  57. }
  58. }
  59. else{
  60.  
  61. money -= 50;
  62. fiftyBill += 1;
  63. }
  64. }
  65. else{
  66.  
  67. money -= 100;
  68. hundredBill += 1;
  69. }
  70. }
  71. else{
  72.  
  73. money -= 200;
  74. twohundredBill += 1;
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81. }
  82. System.out.println("You can use " + twohundredBill + " Two Hundred Dollar Bills");
  83. System.out.println("You can use " + hundredBill + " Hundred Dollar Bills");
  84. System.out.println("You can use " + fiftyBill + " Fifty Dollar Bills");
  85. System.out.println("You can use " + twentyBill + " Twenty Dollar Bills");
  86. System.out.println("You can use " + tenCoin + " Coins of Ten");
  87. System.out.println("You can use " + fiveCoin + " Coins of Five");
  88. System.out.println("You can use " + twoCoin + " Coins of Two");
  89. System.out.println("You can use " + oneCoin + " Coins of One");
  90. }
  91. }
Add Comment
Please, Sign In to add comment