diff --git a/InventoryApp 2.zip b/InventoryApp 2.zip new file mode 100644 index 0000000..b0d15c4 Binary files /dev/null and b/InventoryApp 2.zip differ diff --git a/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/README.md b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/README.md new file mode 100644 index 0000000..75e3d43 --- /dev/null +++ b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/README.md @@ -0,0 +1,74 @@ +# Inventory Management System Application + +**Authors:** +- Jamila Mato (ID: 20220642) +- Haseena Abdullahi (ID: 20220600) + +**Course:** Object-Oriented Programming + +## Project Description + +This is a simple Java console application that simulates an Inventory Management System. It allows users to: + +- Add new products +- View the entire inventory +- Update stock levels +- Delete products + +The system is designed using **Object-Oriented Programming (OOP)** principles such as: + +- **Encapsulation:** Each product's data is kept private within the `Product` class with access provided through getter/setter methods. +- **Association:** The `Inventory` class maintains a collection (list) of `Product` objects and operates on them. +- **Modularity:** Classes are organized by purpose and package to enhance readability and maintainability. + +## Project Structure + +``` +InventoryApp/ +├── src/ +│ └── com/ +│ └── inventory/ +│ ├── model/ +│ │ ├── Product.java +│ │ └── Inventory.java +│ └── main/ +│ └── InventoryApp.java +└── README.md +``` + +## How to Compile and Run + +### 1. Open Terminal or Command Prompt. + +### 2. Navigate to the `src` directory of the project: +```bash +cd path/to/InventoryApp/src +``` + +### 3. Compile all Java files: +```bash +javac com/inventory/model/*.java com/inventory/main/InventoryApp.java +``` + +### 4. Run the application: +```bash +java com.inventory.main.InventoryApp +``` + +## Example Use + +```text +=== Inventory Management System === +1. Add New Product +2. View Inventory +3. Update Stock +4. Delete Product +5. Exit +Choose an option (1-5): +``` + +## Notes + +- Input validation is included to handle invalid numeric input. +- Stock updates prevent negative values. +- Product IDs must be unique. \ No newline at end of file diff --git a/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/main/InventoryApp.java b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/main/InventoryApp.java new file mode 100644 index 0000000..61d06e4 --- /dev/null +++ b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/main/InventoryApp.java @@ -0,0 +1,75 @@ +package com.inventory.main; + +import com.inventory.model.Inventory; +import com.inventory.model.Product; + +import java.util.Scanner; + +public class InventoryApp { + public static void main(String[] args) { + Inventory inventory = new Inventory(); + Scanner scanner = new Scanner(System.in); + boolean running = true; + + while (running) { + System.out.println("\n=== Inventory Management System ==="); + System.out.println("1. Add New Product"); + System.out.println("2. View Inventory"); + System.out.println("3. Update Stock"); + System.out.println("4. Delete Product"); + System.out.println("5. Exit"); + System.out.print("Choose an option (1-5): "); + + try { + int choice = Integer.parseInt(scanner.nextLine()); + switch (choice) { + case 1: + System.out.print("Enter Product ID: "); + String id = scanner.nextLine(); + System.out.print("Enter Product Name: "); + String name = scanner.nextLine(); + System.out.print("Enter Product Description: "); + String desc = scanner.nextLine(); + System.out.print("Enter Product Price: "); + double price = Double.parseDouble(scanner.nextLine()); + System.out.print("Enter Initial Stock Quantity: "); + int qty = Integer.parseInt(scanner.nextLine()); + + Product product = new Product(id, name, desc, price, qty); + inventory.addProduct(product); + break; + + case 2: + inventory.displayInventory(); + break; + + case 3: + System.out.print("Enter Product ID: "); + String updateId = scanner.nextLine(); + System.out.print("Enter Quantity Change (positive to add, negative to remove): "); + int change = Integer.parseInt(scanner.nextLine()); + inventory.updateStock(updateId, change); + break; + + case 4: + System.out.print("Enter Product ID to delete: "); + String deleteId = scanner.nextLine(); + inventory.deleteProduct(deleteId); + break; + + case 5: + running = false; + System.out.println("Exiting the application..."); + break; + + default: + System.out.println("Invalid option. Please choose between 1-5."); + } + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter the correct data type."); + } + } + + scanner.close(); + } +} \ No newline at end of file diff --git a/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Inventory.java b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Inventory.java new file mode 100644 index 0000000..7b4dfa7 --- /dev/null +++ b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Inventory.java @@ -0,0 +1,71 @@ +package com.inventory.model; + +import java.util.ArrayList; +import java.util.List; + +public class Inventory { + private List products; + + public Inventory() { + products = new ArrayList<>(); + } + + public void addProduct(Product product) { + for (Product p : products) { + if (p.getProductId().equalsIgnoreCase(product.getProductId())) { + System.out.println("Product with ID " + product.getProductId() + " already exists."); + return; + } + } + products.add(product); + System.out.println("Product added successfully."); + } + + public Product getProductById(String productId) { + for (Product p : products) { + if (p.getProductId().equalsIgnoreCase(productId)) { + return p; + } + } + return null; + } + + public List getAllProducts() { + return products; + } + + public void updateStock(String productId, int quantityChange) { + Product p = getProductById(productId); + if (p != null) { + int newQuantity = p.getStockQuantity() + quantityChange; + if (newQuantity < 0) { + System.out.println("Cannot reduce stock below 0."); + } else { + p.setStockQuantity(newQuantity); + System.out.println("Stock updated successfully."); + } + } else { + System.out.println("Product not found."); + } + } + + public void deleteProduct(String productId) { + Product p = getProductById(productId); + if (p != null) { + products.remove(p); + System.out.println("Product deleted successfully."); + } else { + System.out.println("Product not found."); + } + } + + public void displayInventory() { + if (products.isEmpty()) { + System.out.println("Inventory is empty."); + } else { + for (Product p : products) { + System.out.println(p); + } + } + } +} \ No newline at end of file diff --git a/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Product.java b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Product.java new file mode 100644 index 0000000..bb9eb82 --- /dev/null +++ b/JAMILA KABIR MATO 20220642 HASEENA ABDULLAHI SADIQ 20220600/InventoryApp 2/InventoryApp 2/src/com/inventory/model/Product.java @@ -0,0 +1,62 @@ +package com.inventory.model; + +public class Product { + private String productId; + private String name; + private String description; + private double price; + private int stockQuantity; + + public Product(String productId, String name, String description, double price, int stockQuantity) { + this.productId = productId; + this.name = name; + this.description = description; + this.price = price; + this.stockQuantity = stockQuantity; + } + + public String getProductId() { + return productId; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public double getPrice() { + return price; + } + + public int getStockQuantity() { + return stockQuantity; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setPrice(double price) { + this.price = price; + } + + public void setStockQuantity(int stockQuantity) { + this.stockQuantity = stockQuantity; + } + + @Override + public String toString() { + return "Product ID: " + productId + + ", Name: " + name + + ", Description: " + description + + ", Price: $" + price + + ", Stock Quantity: " + stockQuantity; + } +} \ No newline at end of file