Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package vendingmachine;
- /**
- *
- * @author Asan
- */
- import java.util.Scanner;
- public class VendingMachine {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- System.out.print("Insert Money: ");
- Scanner input = new Scanner(System.in);
- int money = input.nextInt();
- if (money > 0){
- System.out.println("~~~~~~~~~~~~~~~\nInserted money: "+money+" IQD");
- System.out.println("--------------------------------------------------------------------------------------\n"
- + "| [01] Water (250 IQD) [02] Chips (500 IQD) [03] Chocolate (250 IQD) |\n"
- + "| [04] Cola (500 IQD) [05] Juice (500 IQD) [06] Cookies (500 IQD) |\n"
- + "| [07] Cake (1000 IQD) [08] Jelly (1500 IQD) [09] Candy (500 IQD) |\n"
- + "| [10] Sandwich (2000 IQD) |\n"
- + "| Please enter code for the snack you wish to buy. |\n"
- + "--------------------------------------------------------------------------------------");
- System.out.print("Enter code: ");
- Scanner input2 = new Scanner(System.in);
- int code = input2.nextInt();
- int remaining = money;
- System.out.println("~~~~~~~~~~~~~~~");
- if (code > 0 && code <= 10){
- switch (code){
- case 1: if (remaining-250 > 0){
- System.out.println("You bought water for 250 IQD, you have: "+(remaining-250)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- }
- else System.out.println("Not enough money.");
- break;
- case 2: if (remaining-500 > 0){
- System.out.println("You bought chips for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- }
- else System.out.println("Not enough money.");
- break;
- case 3: if (remaining-250 > 0){
- System.out.println("You bought chocolate for 250 IQD, you have: "+(remaining-250)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- }
- else System.out.println("Not enough money.");
- break;
- case 4: if (remaining-500 > 0){
- System.out.println("You bought cola for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- }
- else System.out.println("Not enough money.");
- break;
- case 5: System.out.println("You bought juice for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- case 6: System.out.println("You bought cookies for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- case 7: System.out.println("You bought cake for 1000 IQD, you have: "+(remaining-1000)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- case 8: System.out.println("You bought jelly for 1500 IQD, you have: "+(remaining-1500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- case 9: System.out.println("You bought candy for 500 IQD, you have: "+(remaining-500)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- case 10: System.out.println("You bought sandwich for 2000 IQD, you have: "+(remaining-2000)+" IQD remaining,\n"
- + "Do you want to buy something else?");
- break;
- }
- }
- else System.out.println("Wrong code.\nHere's your money back! "+money);
- }
- else System.out.println("Wrong value of money.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement