A simple Java console application to split a hostel/room expense equally among roommates and generate a quick settlement report (who owes and who is owed).
- Add multiple roommates (by name)
- Record a single expense:
- Total amount
- Who paid
- Splits the expense equally among all roommates
- Prints a final settlement:
- If balance < 0 → the user owes money
- If balance > 0 → the user should receive money
- If balance = 0 → settled
This repository is intentionally minimal (no Maven/Gradle). All .java files are in the project root:
Main.java— entry point (containspublic static void main)ExpenseManager.java— splitting logicUser.java— user model with balance tracking
- Java JDK 8+ (JDK 11/17 also works)
javacandjavaavailable in your terminal
Check versions:
javac -version
java -version- IntelliJ IDEA / Eclipse / VS Code (with Java extensions)
git clone https://github.com/saksham-stack/Hostel-Expense-Splitter-Java.git
cd Hostel-Expense-Splitter-JavaYou should see:
Main.javaExpenseManager.javaUser.java
Because there is no build tool, compile the .java files directly.
javac Main.java ExpenseManager.java User.javaThis will generate:
Main.classExpenseManager.classUser.class
java Main- Open IntelliJ → Open → select the
Hostel-Expense-Splitter-Javafolder - If asked, set the Project SDK to a JDK (11/17/etc.)
- Open
Main.java - Click the green Run button next to
main()
When you run the program, it asks:
- Number of roommates
- Names of roommates
- Total expense amount
- Name of payer (must match one of the names)
Example:
Input
- Roommates:
3 - Names:
Aman, Neha, Ravi - Amount:
300 - Payer:
Neha
Output (conceptual)
- Aman owes: ₹100.00
- Ravi owes: ₹100.00
- Neha is owed: ₹200.00
- Current version records one expense per run (single expense split).
- Names are taken using
Scanner.next():- Use single-word names (e.g.,
Neha, notNeha Sharma)
- Use single-word names (e.g.,
- Payer name must match one of the roommate names (case-insensitive).
- Each roommate’s share =
totalAmount / numberOfRoommates - For payer:
- balance increases by
(totalAmount - share)
- balance increases by
- For everyone else:
- balance decreases by
share
- balance decreases by
- Support multiple expenses in one session
- Allow expenses with different split ratios (not always equal)
- Store and export a detailed expense history
- Better settlement algorithm (min transfers)
No license specified yet. If you want, add an MIT License file.