Skip to content

saksham-stack/Hostel-Expense-Splitter-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

**HostelSplit** is a Java-based CLI tool designed to simplify shared expense management in university dorms. Built using **Object-Oriented Programming (OOP)**, it utilizes encapsulated data models and the Collections Framework to track roommate balances, calculate fair splits for canteen or supply bills, and provide clear debt settlement reports.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages