Answer to Question #254694 in Java | JSP | JSF for Chakalaka

Question #254694

The application should prompt the owner for a login confirmation code after their have enter the pin (this is used as a security measure kind of a two stage authentication). Once logged in system will then offer the following options to the admin, the privilege to restock/ add new items to the vending machine, change prices, Cash out certain amounts from machine, cash in certain amount, print out a summary of all items in stock, print out amount of cash in categories(How many 100s, 50s up to 5cs)and print out only items that need restocking (all items below 25 need to be restocked, hence the quantity of 25 is the re-order level) or exit, create a menu for this options.


1
Expert's answer
2021-10-22T00:49:07-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