Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added InventoryApp 2.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.inventory.model;

import java.util.ArrayList;
import java.util.List;

public class Inventory {
private List<Product> 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<Product> 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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}