cpu quantity wont change after user buys a cpu

Viewed 26
          case 1:
            for (Items i : globalInventory.cpu) {
                System.out.println(i); 
            }
            //let user select item by item id
            System.out.println("Please select the item by item id: ");
            input.nextLine();
            String itemid = input.nextLine();
            for (Items i : globalInventory.cpu) {
                if (i.getItemID().matches(itemid) ) {
                    System.out.println("Item selected: " + i);
                    System.out.println("Please enter the quantity: ");
                    int quantity = input.nextInt();
                    if (quantity > i.getQuantity()) {
                        System.out.println("Sorry, we don't have that much quantity");
                    } else {
                        i.setQuantity(i.getQuantity() - quantity);
                        cart.add(i, quantity);
                    }
                }
            }

//above are the codes for the driver

Item ID: C1012 Price: RM30000.0 Brand: AMD Quantity: 1 Item Type: cpu CPU Name: Ryzen Threadripper PRO 5995WX Total Cores: 64 Total Threads: 128 Clock Speed: 2.7GHz/4.5GHz

first output

Scanner sc = new Scanner(System.in);
    int x = 0;
    do {
        System.out.println("1. CPU");
        System.out.println("2. RAM");
        System.out.println("3. GPU");
        System.out.println("4. Casing");
        System.out.println("5. PSU");
        System.out.println("6. Storage");
        System.out.println("7. Motherboard");
        System.out.println("8. Exit");
        System.out.print("Enter your choice: ");
        int choice = sc.nextInt();
        switch (choice) {
            case 1:
                for (Items i : globalInventory.cpu) {
                    System.out.println(i);
                }
                break;

driver for printing stocks

public static Items[] cpu = {new cpu("C1000", 1480, "Intel", 1, "cpu", "Intel i7 9700k", 8 , 8, "3.6Ghz/4.9GHz"),
        new cpu("C1001", 1000, "Intel", 1, "cpu", "Intel i5 9600k", 6 , 6, "3.7GHz/4.6GHz"),
        new cpu("C1002", 600, "AMD", 1, "cpu", "AMD Ryzen 5 3600", 6 , 12, "3.6GHz/4.2GHz"),
        new cpu("C1003", 1350, "AMD", 1, "cpu", "AMD Ryzen 7 5700x", 8 , 16, "3.4GHz/4.6GHz"),
        new cpu("C1004", 11250, "Intel", 1, "cpu", "Intel Xeon Platinum 9282 ", 56 , 112, "2.6GHz/3.8GHz"),
        new cpu("C1005", 800, "AMD", 1, "cpu", "AMD Ryzen 5 5600x", 6 , 12, "3.7GHz/4.6GHz"),
        new cpu("C1006", 513, "Intel", 1, "cpu", "Intel i3 8100", 4 , 4, "3.6GHz/3.6GHz"),
        new cpu("C1007", 3600, "AMD", 1, "cpu", "AMD Ryzen 9 5950x", 16 , 32, "3.4GHz/4.9GHz"),
        new cpu("C1008", 2560, "Intel", 1, "cpu", "Intel i9 12900k", 16 , 24, "3.2GHz/5.2GHz"),
        new cpu("C1009", 2470, "AMD", 1, "cpu", "AMD Ryzen 9 5900x", 12 , 24, "3.7GHz/4.8Ghz"),
        new cpu("C1010", 1350, "Intel", 1, "cpu", "Intel i5 12600k", 10 , 16, "3.7GHz/4.9GHz"),
        new cpu("C1011", 715, "AMD", 1, "cpu", "AMD Ryzen 5 5500", 6 , 12, "3.6GHz/4.2GHz"),
        new cpu("C1012", 30000, "AMD", 1, "cpu", "Ryzen Threadripper PRO 5995WX", 64 , 128, "2.7GHz/4.5GHz")};

//these are the object arrays

Item ID: C1012 Price: RM30000.0 Brand: AMD Quantity: 1 Item Type: cpu CPU Name: Ryzen Threadripper PRO 5995WX Total Cores: 64 Total Threads: 128 Clock Speed: 2.7GHz/4.5GHz

output after modifying

0 Answers
Related