The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Design a Group Event Expense Splitter App Using Object-Oriented Design

Overview

The Group Event Expense Splitter App is designed to help users divide shared expenses among a group of people for events, trips, or social gatherings. Each user can enter their expenses, and the app calculates how much each person owes or is owed, ensuring that no one overpays or underpays.

The app will use object-oriented principles to ensure clear structure, maintainability, and scalability. We will design the system using key concepts of object-oriented design (OOD) such as classes, objects, inheritance, and composition.

Core Requirements

  • User Management: Users should be able to sign up, log in, and create/join events.

  • Event Management: Users can create an event, add expenses, and invite participants.

  • Expense Management: Users can input the expenses they’ve paid for, categorizing them as shared or individual.

  • Expense Splitting: The app automatically divides expenses equally or based on custom criteria (e.g., by percentage or amount).

  • Balance Calculation: The app tracks how much each person owes or is owed and calculates the total balance for each participant.

  • Notifications: Alerts when new expenses are added, or the balance is updated.

Key Classes and Relationships

1. User

This class represents a user of the app. Users can add expenses, join events, and view their balances.

python
class User: def __init__(self, user_id, name, email): self.user_id = user_id self.name = name self.email = email self.events = [] # List of events the user is part of self.balance = 0 # Balance for the user (how much they owe or are owed) def join_event(self, event): self.events.append(event) def add_expense(self, expense): expense.add_participant(self)

2. Event

This class represents an event where expenses are shared. It contains a list of users and expenses for the event.

python
class Event: def __init__(self, event_id, event_name, creator): self.event_id = event_id self.event_name = event_name self.creator = creator self.users = [] # Users participating in the event self.expenses = [] # List of expenses for the event def add_user(self, user): self.users.append(user) def add_expense(self, expense): self.expenses.append(expense) def calculate_balances(self): total_expense = sum([expense.amount for expense in self.expenses]) individual_share = total_expense / len(self.users) for user in self.users: user.balance += individual_share - user.total_expense_paid(self) def get_user_balance(self, user): return user.balance

3. Expense

This class represents an expense within an event. Each expense has a payer, participants, and the amount paid. The app calculates how to split this expense among the participants.

python
class Expense: def __init__(self, expense_id, amount, payer, shared=True): self.expense_id = expense_id self.amount = amount self.payer = payer self.shared = shared self.participants = [] # Users sharing the expense def add_participant(self, user): self.participants.append(user) def calculate_share(self): if self.shared: return self.amount / len(self.participants) return self.amount # For non-shared expenses, the entire amount is on the payer

4. Transaction

This class will keep track of all transactions for each user. This includes credits (how much they are owed) or debits (how much they owe).

python
class Transaction: def __init__(self, transaction_id, from_user, to_user, amount): self.transaction_id = transaction_id self.from_user = from_user self.to_user = to_user self.amount = amount def execute(self): self.from_user.balance -= self.amount self.to_user.balance += self.amount

Workflow

  1. Creating an Event:

    • A user (the event creator) creates an event, adding basic information like event name, date, and location.

  2. Adding Participants:

    • The event creator can invite users to join the event. Each user adds their details to the event.

  3. Entering Expenses:

    • Users input their expenses. They can indicate whether the expense is shared or not.

    • If it’s shared, it is split evenly among all participants.

    • Each user can see the total amount they have paid for the event.

  4. Expense Calculation:

    • The app calculates how much each user owes or is owed based on the total expenses and the amount they have contributed.

    • The system checks how much each participant paid and how the expense should be divided.

  5. Balancing the Accounts:

    • The app automatically generates transactions to balance out how much each user owes or is owed.

    • Users can view a summary of the balances and settle any outstanding amounts.

  6. Settling Debts:

    • The app tracks payments and ensures that the debts are paid off.

Sample Usage

python
# Create users alice = User(1, "Alice", "alice@example.com") bob = User(2, "Bob", "bob@example.com") charlie = User(3, "Charlie", "charlie@example.com") # Create event event = Event(101, "Friends Reunion", alice) # Add users to event event.add_user(alice) event.add_user(bob) event.add_user(charlie) # Create expenses expense1 = Expense(201, 150, alice) # Alice paid 150 expense1.add_participant(alice) expense1.add_participant(bob) expense1.add_participant(charlie) expense2 = Expense(202, 100, bob) # Bob paid 100 expense2.add_participant(bob) expense2.add_participant(charlie) # Add expenses to event event.add_expense(expense1) event.add_expense(expense2) # Calculate balances event.calculate_balances() # Check balance for each user print(f"Alice's balance: {alice.balance}") print(f"Bob's balance: {bob.balance}") print(f"Charlie's balance: {charlie.balance}")

Example Output

plaintext
Alice's balance: -50.0 Bob's balance: 25.0 Charlie's balance: 25.0

In this case, Alice has overpaid and is owed $50, while Bob and Charlie each owe $25.

Conclusion

This design leverages the power of object-oriented design to manage users, events, and expenses efficiently. By using classes like User, Event, Expense, and Transaction, we can scale the app and maintain clean, modular code. The app will provide users with a simple interface to manage group expenses, automatically balancing payments to ensure fairness.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About