-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM.txt
38 lines (33 loc) · 1016 Bytes
/
M.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.Assesment1;
import java.util.LinkedList;
import java.util.LinkedList;
class ShoppingCart {
LinkedList<String> cart;
public ShoppingCart() {
cart = new LinkedList<>();
}
// Add an item to the cart
public void addItem(String item) {
cart.add(item);
System.out.println(item + " added to the cart.");
}
// Remove an item from the cart
public void removeItem(String item) {
if (cart.remove(item)) {
System.out.println(item + " removed from the cart.");
} else {
System.out.println(item + " not found in the cart.");
}
}
// View all items in the cart
public void viewCart() {
if (cart.isEmpty()) {
System.out.println("The cart is empty.");
} else {
System.out.println("Items in the cart:");
for (String item : cart) {
System.out.println("- " + item);
}
}
}
}