Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package vendingmachine;
  7.  
  8. /**
  9. *
  10. * @author Asan
  11. */
  12. import java.util.Scanner;
  13. public class VendingMachine {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. System.out.print("Insert Money: ");
  20. Scanner input = new Scanner(System.in);
  21. int money = input.nextInt();
  22.  
  23. if (money > 0){
  24. System.out.println("~~~~~~~~~~~~~~~\nInserted money: "+money+" IQD");
  25. System.out.println("--------------------------------------------------------------------------------------\n"
  26. + "| [01] Water (250 IQD) [02] Chips (500 IQD) [03] Chocolate (250 IQD) |\n"
  27. + "| [04] Cola (500 IQD) [05] Juice (500 IQD) [06] Cookies (500 IQD) |\n"
  28. + "| [07] Cake (1000 IQD) [08] Jelly (1500 IQD) [09] Candy (500 IQD) |\n"
  29. + "| [10] Sandwich (2000 IQD) |\n"
  30. + "| Please enter code for the snack you wish to buy. |\n"
  31. + "--------------------------------------------------------------------------------------");
  32. System.out.print("Enter code: ");
  33. Scanner input2 = new Scanner(System.in);
  34. int code = input2.nextInt();
  35. int remaining = money;
  36. System.out.println("~~~~~~~~~~~~~~~");
  37.  
  38. if (code > 0 && code <= 10){
  39. switch (code){
  40. case 1: if (remaining-250 > 0){
  41. System.out.println("You bought water for 250 IQD, you have: "+(remaining-250)+" IQD remaining,\n"
  42. + "Do you want to buy something else?");
  43. }
  44. else System.out.println("Not enough money.");
  45. break;
  46. case 2: if (remaining-500 > 0){
  47. System.out.println("You bought chips for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
  48. + "Do you want to buy something else?");
  49. }
  50. else System.out.println("Not enough money.");
  51. break;
  52. case 3: if (remaining-250 > 0){
  53. System.out.println("You bought chocolate for 250 IQD, you have: "+(remaining-250)+" IQD remaining,\n"
  54. + "Do you want to buy something else?");
  55. }
  56. else System.out.println("Not enough money.");
  57. break;
  58. case 4: if (remaining-500 > 0){
  59. System.out.println("You bought cola for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
  60. + "Do you want to buy something else?");
  61. }
  62. else System.out.println("Not enough money.");
  63. break;
  64. case 5: System.out.println("You bought juice for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
  65. + "Do you want to buy something else?");
  66. break;
  67. case 6: System.out.println("You bought cookies for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
  68. + "Do you want to buy something else?");
  69. break;
  70. case 7: System.out.println("You bought cake for 1000 IQD, you have: "+(remaining-1000)+" IQD remaining,\n"
  71. + "Do you want to buy something else?");
  72. break;
  73. case 8: System.out.println("You bought jelly for 1500 IQD, you have: "+(remaining-1500)+" IQD remaining,\n"
  74. + "Do you want to buy something else?");
  75. break;
  76. case 9: System.out.println("You bought candy for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
  77. + "Do you want to buy something else?");
  78. break;
  79. case 10: System.out.println("You bought sandwich for 2000 IQD, you have: "+(remaining-2000)+" IQD remaining,\n"
  80. + "Do you want to buy something else?");
  81. break;
  82. }
  83. }
  84. else System.out.println("Wrong code.\nHere's your money back! "+money);
  85. }
  86. else System.out.println("Wrong value of money.");
  87.  
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement