Skip to content

Latest commit

 

History

History
150 lines (104 loc) · 3.1 KB

File metadata and controls

150 lines (104 loc) · 3.1 KB

Hostel-Expense-Splitter-Java

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).


Features

  • 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

Project Structure

This repository is intentionally minimal (no Maven/Gradle). All .java files are in the project root:

  • Main.java — entry point (contains public static void main)
  • ExpenseManager.java — splitting logic
  • User.java — user model with balance tracking

Requirements

Option A (recommended): JDK installed locally

  • Java JDK 8+ (JDK 11/17 also works)
  • javac and java available in your terminal

Check versions:

javac -version
java -version

Option B: Use an IDE

  • IntelliJ IDEA / Eclipse / VS Code (with Java extensions)

Setup / Installation

1) Clone the repository

git clone https://github.com/saksham-stack/Hostel-Expense-Splitter-Java.git
cd Hostel-Expense-Splitter-Java

2) Verify files exist

You should see:

  • Main.java
  • ExpenseManager.java
  • User.java

How to Compile and Run (Terminal)

Because there is no build tool, compile the .java files directly.

1) Compile

javac Main.java ExpenseManager.java User.java

This will generate:

  • Main.class
  • ExpenseManager.class
  • User.class

2) Run

java Main

How to Run (IDE)

IntelliJ IDEA (quick steps)

  1. Open IntelliJ → Open → select the Hostel-Expense-Splitter-Java folder
  2. If asked, set the Project SDK to a JDK (11/17/etc.)
  3. Open Main.java
  4. Click the green Run button next to main()

Example Usage (Sample Input/Output)

When you run the program, it asks:

  1. Number of roommates
  2. Names of roommates
  3. Total expense amount
  4. 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

Notes / Limitations

  • Current version records one expense per run (single expense split).
  • Names are taken using Scanner.next():
    • Use single-word names (e.g., Neha, not Neha Sharma)
  • Payer name must match one of the roommate names (case-insensitive).

How It Works (Logic Summary)

  • Each roommate’s share = totalAmount / numberOfRoommates
  • For payer:
    • balance increases by (totalAmount - share)
  • For everyone else:
    • balance decreases by share

Future Improvements (Optional Ideas)

  • 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)

License

No license specified yet. If you want, add an MIT License file.