Answer to Question #251592 in Java | JSP | JSF for lee

Question #251592
vending machine application which allow user to enter a code of item or pin code used by owner. If item code is entered the balance/cost of item is displayed & prompts user for how many items they want, if the ownerà ƒ ƒ ƒ ¢ € ™s pin is entered the admin menu is displayed. The landing page gives description of machine e.g the Name, address, random items in stock & prices,The application prompts the owner for login confirmation code. Once logged in offer these options to admin, the restock/add new items, change prices, Cash out / cash in certain amount, print summary of items in stock, amount of cash in categories(How many 100s, 50s up to 5cs) & prints only items that need restocking (all items below 25, hence quantity of 25 is the re-order level) or exit, create a menu for this options. When cashing out/in amounts the owner indicates how many 100s, 50s and soon as information is recorded. The customer can buy items & get a receipts . Receipt contains: items names, quantity, price & total, description of the change.
1
Expert's answer
2021-10-15T01:27:54-0400
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int balance = 1000;
        int hundred = 10;
        int fifty = 10;
        int five = 10;
        ArrayList<String> names = new ArrayList<>();
        names.add("Cola");
        names.add("Bread");
        names.add("Egg");
        ArrayList<Integer> prices = new ArrayList<>();
        prices.add(65);
        prices.add(15);
        prices.add(10);
        ArrayList<Integer> quantities = new ArrayList<>();
        quantities.add(100);
        quantities.add(50);
        quantities.add(30);

        while (true) {
            System.out.println("Code: ");
            int code = in.nextInt();
            if (code >= 0 && code < quantities.size()) {
                System.out.println("Balance: " + balance);
                System.out.println("Cost: " + prices.get(code));
                System.out.println("Quantity:");
                int quantity = in.nextInt();
                System.out.println("Receipt:");
                System.out.println("Name: " + names.get(code) + " Quantity: " + quantities +
                        " Price: " + prices.get(code) + " Total: " + (quantity * prices.get(code)));
                hundred += (quantity * prices.get(code)) / 100;
                fifty += ((quantity * prices.get(code)) % 100) / 50;
                five += (((quantity * prices.get(code)) % 100) % 50) / 5;
                System.out.println("Change: " + (balance - quantity * prices.get(code)));
            } else if (code == 98989) {
                System.out.println("Hola-Lula, North pole");
                for (int i = 0; i < quantities.size(); i++) {
                    System.out.println(i + "Name: " + names.get(i) + " Quantity: " + quantities.get(i) +
                            " Price: " + prices.get(i));
                }
                System.out.println("Login confirmation code:");
                int confirmationCode = in.nextInt();
                if (confirmationCode == 89898) {
                    System.out.println("1. Restock\n" +
                            "2. Add item\n" +
                            "3. Change price\n" +
                            "4. Cash out\n" +
                            "5. Cash in\n" +
                            "6. Print summary\n" +
                            "7. Amount of cash\n" +
                            "8. Print only restocking\n" +
                            "9. Exit");
                    switch (in.nextInt()) {
                        case 1:
                            System.out.println("Code, Quantity: ");
                            quantities.set(in.nextInt(), in.nextInt());
                            break;
                        case 2:
                            System.out.println("Name: ");
                            names.add(in.next());
                            System.out.println("Quantity: ");
                            quantities.add(in.nextInt());
                            System.out.println("Price: ");
                            prices.add(in.nextInt());
                            break;
                        case 3:
                            System.out.println("Code, New Price: ");
                            prices.set(in.nextInt(), in.nextInt());
                            break;
                        case 4:
                            System.out.println("1. 100\n" +
                                    "2. 50\n" +
                                    "3. 5");
                            System.out.println("Amount: ");
                            switch (in.nextInt()) {
                                case 100:
                                    hundred -= in.nextInt();
                                    break;
                                case 50:
                                    fifty -= in.nextInt();
                                    break;
                                case 5:
                                    five -= in.nextInt();
                                    break;
                            }
                            break;
                        case 5:
                            System.out.println("1. 100\n" +
                                    "2. 50\n" +
                                    "3. 5");
                            System.out.println("Amount: ");
                            switch (in.nextInt()) {
                                case 100:
                                    hundred += in.nextInt();
                                    break;
                                case 50:
                                    fifty += in.nextInt();
                                    break;
                                case 5:
                                    five += in.nextInt();
                                    break;
                            }
                            break;
                        case 6:
                            System.out.println("Summary:");
                            for (int i = 0; i < quantities.size(); i++) {
                                System.out.println(i + "Name: " + names.get(i) + " Quantity: " + quantities.get(i) +
                                        " Price: " + prices.get(i));
                            }
                            break;
                        case 7:
                            System.out.println("100: " + hundred);
                            System.out.println("50: " + fifty);
                            System.out.println("5: " + five);
                            break;
                        case 8:
                            System.out.println("Re-order:");
                            for (int i = 0; i < quantities.size(); i++) {
                                if (quantities.get(i) < 25) {
                                    System.out.println(i);
                                }
                            }
                            break;
                        case 9:
                            System.exit(0);
                    }
                }
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS