Q008_Shopping_Cart_program in java
Q008_Shopping_Cart_program in java
import java.util.ArrayList;
import java.util.Scanner;
class Item {
public Item() {
this.itemCode = code;
this.itemName = name;
this.itemQty = qty;
if (itemArr.isEmpty()) {
System.out.println("Cart is Empty");
} else {
}
public int getItemCode() {
return itemCode;
int choice;
do {
System.out.println("4. Exit");
choice = scanner.nextInt();
switch (choice) {
case 1:
scanner.nextLine();
case 2:
if (item.getItemCode() == removeCode) {
cart.remove(item);
found = true;
Item.display(cart);
break;
if (!found) {
break;
case 3:
Item.display(cart);
break;
case 4:
System.out.println("Thank you!!!");
break;
default:
}
} while (choice != 4);
scanner.close();
Output:
Input and Output 1:
Shopping cart menu
1. Insert new item in cart
2. Remove an item from cart
3. View cart items
4. Exit
Enter your choice
1
Enter item code:
101
Enter item name:
ball
Enter item quantity:
4
Shopping cart menu
1. Insert new item in cart
2. Remove an item from cart
3. View cart items
4. Exit
Enter your choice
1
Enter item code:
102
Enter item name:
book
Enter item quantity:
3
Shopping cart menu
1. Insert new item in cart
2. Remove an item from cart
3. View cart items
4. Exit
Enter your choice
3
Item code: 101
Item name: ball
Item quantity: 4
Item code: 102
Item name: book
Item quantity: 3
Shopping cart menu
1. Insert new item in cart
2. Remove an item from cart
3. View cart items
4. Exit
Enter your choice
4
Thank you!!!