A simple Java CLI application to manage kitchen grocery items. Built as a university Object-Oriented Programming (OOP) assignment.
Managing kitchen inventory manually is inconvenient. Items run out, expire, or get forgotten. This application provides a simple menu-driven system to keep track of grocery items stored in the kitchen.
Build a beginner-friendly Java application that demonstrates core OOP concepts:
- Classes and Objects
- Encapsulation
- Inheritance
- Functions (methods)
- Debugging
- Add Item — store a new grocery item
- View Items — display all items in the inventory
- Search Item — find an item by name
- Update Quantity — change the quantity of an existing item
- Delete Item — remove an item from the inventory
- Exit — close the application
- Language : Java (Core Java only)
- Interface : Command Line Interface (CLI)
- Input : Scanner class
- Storage : ArrayList (in-memory, no database)
KitchenInventoryManager/
│
├── src/
│ ├── Item.java → Base class (Encapsulation)
│ ├── PerishableItem.java → Subclass (Inheritance)
│ ├── Inventory.java → CRUD operations on ArrayList
│ └── Main.java → Menu, input handling, driver code
│
├── README.md
├── DebuggingReport.md
└── .gitignore
The base class that represents a single grocery item.
All fields are private (Encapsulation):
id→ unique item numbername→ item name (e.g. Milk)category→ item category (e.g. Dairy)quantity→ how many units are availableexpiryDate→ expiry date as a string (e.g. 25-07-2026) or N/A
Methods:
displayItem()→ prints all item details on screen- Getters and Setters for every field
Extends Item to demonstrate Inheritance.
- Uses
super()in its constructor to pass values toItem - Overrides
displayItem()using@Overrideto also print "Type : Perishable Item"
This class is intentionally kept simple. Its only purpose is to show how one class can inherit from another in Java.
Manages the collection of items using ArrayList<Item>.
Methods:
addItem(Item item)→ adds an item to the listviewItems()→ prints all itemssearchItem(String name)→ finds items by nameupdateItem(int id, int qty)→ updates quantity for a given IDdeleteItem(int id)→ removes item by ID
No other logic exists in this class.
The entry point of the application.
Responsibilities:
- Displays the menu using
printMenu() - Reads user input using
Scanner - Calls appropriate
Inventorymethods based on the user's choice - Contains a helper method
readInt()to safely read integers
| Operation | Method Called | What Happens |
|---|---|---|
| Create | addItem() |
New Item object added to ArrayList |
| Read | viewItems() |
Loops through list and prints items |
| Search | searchItem() |
Finds item by matching name |
| Update | updateItem() |
Finds item by ID, sets new quantity |
| Delete | deleteItem() |
Finds item by ID, removes from list |
All fields in Item.java are declared private.
They cannot be accessed directly from outside the class.
Access is provided only through public getter and setter methods.
Example:
private int quantity; // cannot be accessed directly
public int getQuantity() { // controlled read access
return quantity;
}
public void setQuantity(int quantity) { // controlled write access
this.quantity = quantity;
}PerishableItem extends Item.
It inherits all fields and methods from Item without rewriting them.
It overrides displayItem() to add extra output.
Example:
public class PerishableItem extends Item {
public PerishableItem(int id, String name, String category,
int quantity, String expiryDate) {
super(id, name, category, quantity, expiryDate); // calls Item constructor
}
@Override
public void displayItem() {
super.displayItem(); // calls Item's method
System.out.println("Type : Perishable Item");
}
}Four classes are defined: Item, PerishableItem, Inventory, Main.
Objects are created in Main.java:
Item item = new Item(1, "Rice", "Grains", 10, "N/A");
PerishableItem milk = new PerishableItem(2, "Milk", "Dairy", 5, "25-07-2026");Every action in the project is a method:
addItem(),viewItems(),searchItem(),updateItem(),deleteItem()printMenu(),readInt(),displayItem()
An intentional bug was introduced in updateItem() where quantity was
accidentally increased instead of replaced. The bug was identified using
the IDE debugger and fixed. See DebuggingReport.md for the full walkthrough.
| Requirement | How it is satisfied |
|---|---|
| Functions | Methods like addItem(), viewItems(), displayItem(), etc. |
| Classes | Item, PerishableItem, Inventory, Main |
| Objects | Item and PerishableItem instances created in Main.java |
| Encapsulation | Private fields + public getters/setters in Item.java |
| Inheritance | PerishableItem extends Item with super() and @Override |
| Debugging | Bug introduced, documented, debugged, and fixed |
User launches app
↓
Menu is displayed
↓
User selects option (1–6)
↓
Main.java reads input and calls Inventory method
↓
Inventory performs operation on ArrayList<Item>
↓
Result is printed to console
↓
Menu repeats until user chooses Exit (6)
Open PowerShell or Command Prompt.
Navigate to the project folder:
cd "C:\Users\RuchaParmar\Downloads\Oops_Project\KitchenInventoryManager"
Compile all Java files:
javac src\Item.java src\PerishableItem.java src\Inventory.java src\Main.java
If javac is not found in PATH, use the full path:
& "C:\Program Files\Java\jdk-26.0.1\bin\javac.exe" src\Item.java src\PerishableItem.java src\Inventory.java src\Main.java
Run the application after compiling:
java src.Main
If java is not found in PATH, use the full path:
& "C:\Program Files\Java\jdk-26.0.1\bin\java.exe" src.Main
Welcome to Kitchen Inventory Manager!
==============================
Kitchen Inventory Manager
==============================
1. Add Item
2. View Items
3. Search Item
4. Update Quantity
5. Delete Item
6. Exit
==============================
Enter your choice: 1
--- Add New Item ---
Enter name: Milk
Enter category (e.g. Dairy, Grains): Dairy
Enter quantity: 5
Enter expiry date (dd-MM-yyyy) or N/A: 25-07-2026
Is this a perishable item? (y/n): y
Item added successfully!
- Save inventory to a file so data persists after the program exits
- Add expiry date validation
- Add a low stock alert when quantity drops below a threshold
- Allow updating item name and category, not just quantity
Name : Rucha Parmar
Task of : Oops
College : Charusat University
Year : Fourth Year Engineering