-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventorySystem.java
More file actions
83 lines (73 loc) · 4.31 KB
/
Copy pathInventorySystem.java
File metadata and controls
83 lines (73 loc) · 4.31 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//Main class
import javax.swing.JOptionPane;
public class InventorySystem {
public static void main(String[] args) {
Inventory inventory = new Inventory();
inventory.addItem(new AndroidPhone("Samsung", "Galaxy S21", 999.99, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Samsung", "Galaxy S20", 799.99, "Android smartphone", 5));
inventory.addItem(new AndroidPhone("Xiaomi", "Redmi Note 10", 299.99, "Android smartphone", 8));
inventory.addItem(new AndroidPhone("Sony", "Xperia 1 III", 1199.99, "Android smartphone", 3));
inventory.addItem(new IPhone("Apple", "iPhone 12", 1099.99, "iOS smartphone", 7));
inventory.addItem(new IPhone("Apple", "iPhone 11", 699.99, "iOS smartphone", 4));
inventory.addItem(new AndroidPhone("Opp", "A50", 493.99, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Vivo", "Y20", 200.99, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Samsung", " Galaxt A05s", 250.99, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("One plus", "Ai Note", 400.00, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Symphony", "tR 67", 178.99, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Google", "Pixel 7 pro", 650.34, "Android smartphone", 10));
inventory.addItem(new AndroidPhone("Redmi", "Note 9", 64.99, "Android smartphone", 10));
String[] options = {"View Inventory", "Add Item", "Remove Item", "Filter by Price","Purchase Item", "Exit"};
while (true) {
int choice = JOptionPane.showOptionDialog(null, "Select an option:", "Inventory System", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
switch (choice) {
case 0:
inventory.displayInventory();
break;
case 1:
addNewItem(inventory);
break;
case 2:
removeItem(inventory);
break;
case 3:
purchaseItem(inventory);
break;
case 4:
filterByPrice(inventory);
break;
case 5:
JOptionPane.showMessageDialog(null, "Exiting inventory system.");
System.exit(0);
}
}
}
private static void addNewItem(Inventory inventory) {
String brand = JOptionPane.showInputDialog(null, "Enter brand:");
String model = JOptionPane.showInputDialog(null, "Enter model:");
double price = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter price:"));
String description = JOptionPane.showInputDialog(null, "Enter description:");
int quantity = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter quantity:"));
String phoneType = JOptionPane.showInputDialog(null, "Enter phone type (Android/iPhone):");
if (phoneType.equalsIgnoreCase("Android")) {
inventory.addItem(new AndroidPhone(brand, model, price, description, quantity));
} else if (phoneType.equalsIgnoreCase("iPhone")) {
inventory.addItem(new IPhone(brand, model, price, description, quantity));
} else {
JOptionPane.showMessageDialog(null, "Invalid phone type.");
}
JOptionPane.showMessageDialog(null, "Item added successfully.");
}
private static void removeItem(Inventory inventory) {
String modelToRemove = JOptionPane.showInputDialog(null, "Enter model to remove:");
inventory.removeItem(modelToRemove);
}
private static void purchaseItem(Inventory inventory) {
String model = JOptionPane.showInputDialog(null, "Enter model of the item to purchase:");
int quantity = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter quantity to purchase:"));
inventory.purchaseItem(model, quantity);
}
private static void filterByPrice(Inventory inventory) {
double minPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter minimum price:"));
double maxPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter maximum price:"));
}
}