presudo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ // book list.js
2
+
3
+ const BookList = () => {
4
+
5
+ return(
6
+ <div className="book-list-container"> {/* Add a class to the container */}
7
+ <h2>Book List</h2>
8
+
9
+ <input placeholder="Title" ></input>
10
+ <input placeholder="Author" ></input>
11
+
12
+ <p>Add Book</p>
13
+
14
+ <p>Remove</p>
15
+
16
+ </div>
17
+ );
18
+ };
19
+
20
+ export default BookList;
21
+
22
+ ---------------------------------------------------------------------------------------------------------------------------------------
23
+
24
+ // BookContext.js
25
+
26
+ import React, { createContext, useState } from 'react';
27
+
28
+ // create context of books
29
+
30
+ export const BookProvider = ({ children }) => {
31
+ // set up book provider here managing books states with set method
32
+
33
+ return <>{children}</>;
34
+ };
35
+
36
+
37
+ ---------------------------------------------------------------------------------------------------------------------------------------
38
+
39
+
40
+ // LoggerContext.js
41
+
42
+ import React, { createContext } from 'react';
43
+
44
+ // create Logger Context
45
+
46
+ export const LoggerProvider = ({ children }) => {
47
+ // set up log provider here managing logInfo and logError
48
+
49
+ return <>{children}</>;
50
+ };
51
+
@@ -0,0 +1,274 @@
1
+ //Product Management System
2
+
3
+
4
+ // Product.ts
5
+ class Product {
6
+ productId: string;
7
+ name: string;
8
+ price: number;
9
+ quantity: number;
10
+
11
+ constructor(productId: string, name: string, price: number, quantity: number) {
12
+ this.productId = productId;
13
+ this.name = name;
14
+ this.price = price;
15
+ this.quantity = quantity;
16
+ }
17
+
18
+ // Update stock after a sale
19
+ updateStock(amountSold: number): void {
20
+ if (this.quantity >= amountSold) {
21
+ this.quantity -= amountSold;
22
+ console.log(`${this.name}: Sold ${amountSold} items. Remaining stock: ${this.quantity}`);
23
+ } else {
24
+ console.log(`${this.name}: Not enough stock to sell.`);
25
+ }
26
+ }
27
+
28
+ // Display product details
29
+ displayProduct(): void {
30
+ console.log(`ID: ${this.productId}, Name: ${this.name}, Price: $${this.price}, Quantity: ${this.quantity}`);
31
+ }
32
+ }
33
+
34
+
35
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
36
+
37
+ // ProductManager.ts
38
+ class ProductManager {
39
+ private products: Product[] = [];
40
+
41
+ // Add a new product
42
+ addProduct(product: Product): void {
43
+ this.products.push(product);
44
+ console.log(`${product.name} added to the inventory.`);
45
+ }
46
+
47
+ // Display all products
48
+ displayAllProducts(): void {
49
+ console.log("\n--- Product List ---");
50
+ this.products.forEach(product => product.displayProduct());
51
+ }
52
+
53
+ // Filter products based on price range
54
+ filterByPrice(minPrice: number, maxPrice: number): Product[] {
55
+ return this.products.filter(product => product.price >= minPrice && product.price <= maxPrice);
56
+ }
57
+
58
+ // Sort products by price (ascending)
59
+ sortByPriceAscending(): void {
60
+ this.products.sort((a, b) => a.price - b.price);
61
+ console.log("\n--- Products Sorted by Price (Ascending) ---");
62
+ this.displayAllProducts();
63
+ }
64
+
65
+ // Sort products by quantity (descending)
66
+ sortByQuantityDescending(): void {
67
+ this.products.sort((a, b) => b.quantity - a.quantity);
68
+ console.log("\n--- Products Sorted by Quantity (Descending) ---");
69
+ this.displayAllProducts();
70
+ }
71
+
72
+ // Process sale and update product stock
73
+ processSale(productId: string, quantity: number): void {
74
+ const product = this.products.find(product => product.productId === productId);
75
+ if (product) {
76
+ product.updateStock(quantity);
77
+ } else {
78
+ console.log("Product not found.");
79
+ }
80
+ }
81
+ }
82
+
83
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
84
+
85
+ // Main.ts
86
+ const manager = new ProductManager();
87
+
88
+ // Creating some products
89
+ const product1 = new Product("P001", "Laptop", 1000, 50);
90
+ const product2 = new Product("P002", "Smartphone", 700, 100);
91
+ const product3 = new Product("P003", "Headphones", 150, 200);
92
+ const product4 = new Product("P004", "Keyboard", 50, 300);
93
+
94
+ // Adding products to the inventory
95
+ manager.addProduct(product1);
96
+ manager.addProduct(product2);
97
+ manager.addProduct(product3);
98
+ manager.addProduct(product4);
99
+
100
+ // Displaying all products
101
+ manager.displayAllProducts();
102
+
103
+ // Filter products within a price range (e.g., $100 - $1000)
104
+ console.log("\n--- Filtered Products (Price: $100 - $1000) ---");
105
+ const filteredProducts = manager.filterByPrice(100, 1000);
106
+ filteredProducts.forEach(product => product.displayProduct());
107
+
108
+ // Sorting products by price in ascending order
109
+ manager.sortByPriceAscending();
110
+
111
+ // Sorting products by quantity in descending order
112
+ manager.sortByQuantityDescending();
113
+
114
+ // Process a sale (e.g., selling 5 laptops)
115
+ manager.processSale("P001", 5);
116
+
117
+ // Attempting to sell more products than in stock
118
+ manager.processSale("P003", 250); // Not enough stock for headphones
119
+
120
+ // Display updated products
121
+ manager.displayAllProducts();
122
+
123
+
124
+
125
+
126
+
127
+ ---------------------------------------------------------------------------------------------
128
+ ----------------------------------
129
+ ------------------------------------------------------------------------------
130
+ ---------------------------------------------------------------------------------------------
131
+ ----------------------------------
132
+ ------------------------------------------------------------------------------
133
+
134
+ // Another format---------------------------------
135
+
136
+
137
+
138
+
139
+
140
+ // Product.ts
141
+
142
+ class Product {
143
+ productId: string;
144
+ name: string;
145
+ price: number;
146
+ quantity: number;
147
+
148
+ constructor(productId: string, name: string, price: number, quantity: number) {
149
+ this.productId = productId;
150
+ this.name = name;
151
+ this.price = price;
152
+ this.quantity = quantity;
153
+ }
154
+
155
+ // Update stock after a sale
156
+ updateStock(amountSold: number): void {
157
+ if (this.quantity >= amountSold) {
158
+ this.quantity -= amountSold;
159
+ console.log(`${this.name}: Sold ${amountSold} items. Remaining stock: ${this.quantity}`);
160
+ } else {
161
+ console.log(`${this.name}: Not enough stock to sell.`);
162
+ }
163
+ }
164
+
165
+ // Display product details
166
+ displayProduct(): void {
167
+ console.log(`ID: ${this.productId}, Name: ${this.name}, Price: $${this.price}, Quantity: ${this.quantity}`);
168
+ }
169
+ }
170
+
171
+ export { Product };
172
+
173
+ ---------------------------------------------------------------------------------------------
174
+
175
+ 2. ProductManager.ts (Managing the Inventory)
176
+ typescript
177
+ Copy code
178
+ // ProductManager.ts
179
+
180
+ import { Product } from './Product'; // Adjust the import path if necessary
181
+
182
+ class ProductManager {
183
+ private products: Product[] = [];
184
+
185
+ // Add a new product to the inventory
186
+ addProduct(product: Product): void {
187
+ this.products.push(product);
188
+ console.log(`${product.name} added to the inventory.`);
189
+ }
190
+
191
+ // Display all products in the inventory
192
+ displayAllProducts(): void {
193
+ console.log("\n--- Product List ---");
194
+ this.products.forEach(product => product.displayProduct());
195
+ }
196
+
197
+ // Filter products based on a price range
198
+ filterByPrice(minPrice: number, maxPrice: number): Product[] {
199
+ return this.products.filter(product => product.price >= minPrice && product.price <= maxPrice);
200
+ }
201
+
202
+ // Sort products by price (ascending order)
203
+ sortByPriceAscending(): void {
204
+ this.products.sort((a, b) => a.price - b.price);
205
+ console.log("\n--- Products Sorted by Price (Ascending) ---");
206
+ this.displayAllProducts();
207
+ }
208
+
209
+ // Sort products by quantity (descending order)
210
+ sortByQuantityDescending(): void {
211
+ this.products.sort((a, b) => b.quantity - a.quantity);
212
+ console.log("\n--- Products Sorted by Quantity (Descending) ---");
213
+ this.displayAllProducts();
214
+ }
215
+
216
+ // Process a sale and update the stock of the product
217
+ processSale(productId: string, quantity: number): void {
218
+ const product = this.products.find(product => product.productId === productId);
219
+ if (product) {
220
+ product.updateStock(quantity);
221
+ } else {
222
+ console.log("Product not found.");
223
+ }
224
+ }
225
+ }
226
+
227
+ export { ProductManager };
228
+
229
+ ---------------------------------------------------------------------------------------------
230
+
231
+ 3. Main.ts (Putting Everything Together)
232
+ typescript
233
+ Copy code
234
+ // Main.ts
235
+
236
+ import { Product } from './Product'; // Adjust the import path
237
+ import { ProductManager } from './ProductManager'; // Adjust the import path
238
+
239
+ const manager = new ProductManager();
240
+
241
+ // Creating some products
242
+ const product1 = new Product("P001", "Laptop", 1000, 50);
243
+ const product2 = new Product("P002", "Smartphone", 700, 100);
244
+ const product3 = new Product("P003", "Headphones", 150, 200);
245
+ const product4 = new Product("P004", "Keyboard", 50, 300);
246
+
247
+ // Adding products to the inventory
248
+ manager.addProduct(product1);
249
+ manager.addProduct(product2);
250
+ manager.addProduct(product3);
251
+ manager.addProduct(product4);
252
+
253
+ // Displaying all products
254
+ manager.displayAllProducts();
255
+
256
+ // Filter products within a price range (e.g., $100 - $1000)
257
+ console.log("\n--- Filtered Products (Price: $100 - $1000) ---");
258
+ const filteredProducts = manager.filterByPrice(100, 1000);
259
+ filteredProducts.forEach(product => product.displayProduct());
260
+
261
+ // Sorting products by price in ascending order
262
+ manager.sortByPriceAscending();
263
+
264
+ // Sorting products by quantity in descending order
265
+ manager.sortByQuantityDescending();
266
+
267
+ // Process a sale (e.g., selling 5 laptops)
268
+ manager.processSale("P001", 5);
269
+
270
+ // Attempting to sell more products than in stock
271
+ manager.processSale("P003", 250); // Not enough stock for headphones
272
+
273
+ // Display updated products
274
+ manager.displayAllProducts();
@@ -0,0 +1,130 @@
1
+ // managing a delivery service
2
+
3
+
4
+ # Import necessary libraries
5
+ from abc import ABC, abstractmethod
6
+
7
+ # 1. Abstract Base Class for a Delivery Service
8
+ class DeliveryService(ABC):
9
+ @abstractmethod
10
+ def create_order(self, order_id, customer_name, delivery_address, items):
11
+ pass
12
+
13
+ @abstractmethod
14
+ def update_order(self, order_id, status):
15
+ pass
16
+
17
+ @abstractmethod
18
+ def cancel_order(self, order_id):
19
+ pass
20
+
21
+ @abstractmethod
22
+ def display_order(self, order_id):
23
+ pass
24
+
25
+
26
+ # 2. Concrete class for managing orders in a Delivery Service
27
+ class OrderManagement(DeliveryService):
28
+ def __init__(self):
29
+ self.orders = {}
30
+
31
+ def create_order(self, order_id, customer_name, delivery_address, items):
32
+ if order_id in self.orders:
33
+ raise ValueError("Order ID already exists.")
34
+ self.orders[order_id] = {
35
+ 'customer_name': customer_name,
36
+ 'delivery_address': delivery_address,
37
+ 'items': items,
38
+ 'status': 'Pending'
39
+ }
40
+ print(f"Order {order_id} created for {customer_name}.")
41
+
42
+ def update_order(self, order_id, status):
43
+ if order_id not in self.orders:
44
+ raise ValueError("Order ID not found.")
45
+ self.orders[order_id]['status'] = status
46
+ print(f"Order {order_id} status updated to {status}.")
47
+
48
+ def cancel_order(self, order_id):
49
+ if order_id not in self.orders:
50
+ raise ValueError("Order ID not found.")
51
+ del self.orders[order_id]
52
+ print(f"Order {order_id} has been canceled.")
53
+
54
+ def display_order(self, order_id):
55
+ if order_id not in self.orders:
56
+ raise ValueError("Order ID not found.")
57
+ order = self.orders[order_id]
58
+ print(f"Order ID: {order_id}")
59
+ print(f"Customer Name: {order['customer_name']}")
60
+ print(f"Delivery Address: {order['delivery_address']}")
61
+ print(f"Items: {', '.join(order['items'])}")
62
+ print(f"Status: {order['status']}")
63
+
64
+
65
+ # 3. Switch Case for Menu
66
+ def switch_case(option, order_manager):
67
+ menu = {
68
+ 1: order_manager.create_order,
69
+ 2: order_manager.update_order,
70
+ 3: order_manager.cancel_order,
71
+ 4: order_manager.display_order,
72
+ }
73
+
74
+ if option in menu:
75
+ return menu[option]
76
+ else:
77
+ raise ValueError("Invalid option!")
78
+
79
+
80
+ # 4. Delivery Service Menu (User Interface)
81
+ class DeliveryServiceMenu:
82
+ def __init__(self):
83
+ self.order_manager = OrderManagement()
84
+
85
+ def show_menu(self):
86
+ print("\nDelivery Service Menu")
87
+ print("1. Create Order")
88
+ print("2. Update Order Status")
89
+ print("3. Cancel Order")
90
+ print("4. Display Order Details")
91
+ print("5. Exit")
92
+
93
+ def run(self):
94
+ while True:
95
+ self.show_menu()
96
+ try:
97
+ option = int(input("Choose an option: "))
98
+ if option == 5:
99
+ print("Exiting the system.")
100
+ break
101
+
102
+ if option == 1:
103
+ order_id = input("Enter Order ID: ")
104
+ customer_name = input("Enter Customer Name: ")
105
+ delivery_address = input("Enter Delivery Address: ")
106
+ items = input("Enter Items (comma-separated): ").split(',')
107
+ switch_case(option, self.order_manager)(order_id, customer_name, delivery_address, items)
108
+
109
+ elif option == 2:
110
+ order_id = input("Enter Order ID: ")
111
+ status = input("Enter New Status: ")
112
+ switch_case(option, self.order_manager)(order_id, status)
113
+
114
+ elif option == 3:
115
+ order_id = input("Enter Order ID: ")
116
+ switch_case(option, self.order_manager)(order_id)
117
+
118
+ elif option == 4:
119
+ order_id = input("Enter Order ID: ")
120
+ switch_case(option, self.order_manager)(order_id)
121
+
122
+ except Exception as e:
123
+ print(f"Error: {e}")
124
+ continue
125
+
126
+
127
+ # 5. Main Function to Run the Application
128
+ if __name__ == "__main__":
129
+ menu = DeliveryServiceMenu()
130
+ menu.run()
@@ -0,0 +1,200 @@
1
+ Design a Python module for managing an online shopping cart system
2
+
3
+
4
+ from abc import ABC, abstractmethod
5
+
6
+
7
+ # -------------------- Abstraction --------------------
8
+
9
+ class Product(ABC):
10
+
11
+ def __init__(self, name, price):
12
+
13
+ self.name = name
14
+
15
+ self.price = price
16
+
17
+ @abstractmethod
18
+
19
+ def get_price(self):
20
+
21
+ pass
22
+
23
+
24
+ # -------------------- Inheritance & Polymorphism --------------------
25
+
26
+ class RegularProduct(Product):
27
+
28
+ def get_price(self):
29
+
30
+ return self.price
31
+
32
+
33
+ class DiscountedProduct(Product):
34
+
35
+ def get_price(self):
36
+
37
+ return self.price - (self.price * 0.1) # 10% discount
38
+
39
+
40
+ # -------------------- Cart Class --------------------
41
+
42
+ class ShoppingCart:
43
+
44
+ def __init__(self):
45
+
46
+ self.items = []
47
+
48
+ def add_item(self, product):
49
+
50
+ self.items.append(product)
51
+
52
+ def remove_item(self, name):
53
+
54
+ for item in self.items:
55
+
56
+ if item.name == name:
57
+
58
+ self.items.remove(item)
59
+
60
+ return True
61
+
62
+ return False
63
+
64
+ def calculate_total(self):
65
+
66
+ total = 0
67
+
68
+ for item in self.items:
69
+
70
+ total += item.get_price()
71
+
72
+ return int(total)
73
+
74
+
75
+ # -------------------- Shopping System --------------------
76
+
77
+ class OnlineShop:
78
+
79
+ def __init__(self):
80
+
81
+ self.catalog = {}
82
+
83
+ self.cart = ShoppingCart()
84
+
85
+ def add_product(self, product_type, name, price):
86
+
87
+ try:
88
+
89
+ if product_type == "REGULAR":
90
+
91
+ self.catalog[name] = RegularProduct(name, price)
92
+
93
+ elif product_type == "DISCOUNT":
94
+
95
+ self.catalog[name] = DiscountedProduct(name, price)
96
+
97
+ else:
98
+
99
+ raise ValueError
100
+
101
+ except Exception:
102
+
103
+ pass
104
+
105
+ def add_to_cart(self, name):
106
+
107
+ try:
108
+
109
+ if name not in self.catalog:
110
+
111
+ raise KeyError
112
+
113
+ self.cart.add_item(self.catalog[name])
114
+
115
+ except Exception:
116
+
117
+ pass
118
+
119
+ def remove_from_cart(self, name):
120
+
121
+ self.cart.remove_item(name)
122
+
123
+ def get_bill(self):
124
+
125
+ return self.cart.calculate_total()
126
+
127
+
128
+ # -------------------- Switch Case Controller --------------------
129
+
130
+ def process_commands(commands):
131
+
132
+ shop = OnlineShop()
133
+
134
+ result = []
135
+
136
+ for command in commands:
137
+
138
+ try:
139
+
140
+ parts = command.split()
141
+
142
+ action = parts[0]
143
+
144
+ match action:
145
+
146
+ case "ADD_PRODUCT":
147
+
148
+ product_type = parts[1]
149
+
150
+ name = parts[2]
151
+
152
+ price = int(parts[3])
153
+
154
+ shop.add_product(product_type, name, price)
155
+
156
+ case "ADD_CART":
157
+
158
+ name = parts[1]
159
+
160
+ shop.add_to_cart(name)
161
+
162
+ case "REMOVE_CART":
163
+
164
+ name = parts[1]
165
+
166
+ shop.remove_from_cart(name)
167
+
168
+ case "BILL":
169
+
170
+ result.append(str(shop.get_bill()))
171
+
172
+ case _:
173
+
174
+ pass
175
+
176
+ except Exception:
177
+
178
+ pass
179
+
180
+ return result
181
+
182
+
183
+ # -------------------- Main --------------------
184
+
185
+ if __name__ == "__main__":
186
+
187
+ n = int(input())
188
+
189
+ commands = []
190
+
191
+ for _ in range(n):
192
+
193
+ commands.append(input())
194
+
195
+ output = process_commands(commands)
196
+
197
+ for value in output:
198
+
199
+ print(value)
200
+