Design and implement a Splitwise System that allows users to split expenses among groups and individuals. The system should handle expense tracking, balance calculations, and settlement of debts between users.
-
User Management:
- Create and manage user profiles
- Track user balances
- Handle user relationships
-
Group Management:
- Create and manage groups
- Add/remove members
- Track group expenses
-
Expense Management:
- Add expenses to groups or individuals
- Support different split types (EQUAL, EXACT, PERCENTAGE)
- Track expense history
-
Balance Management:
- Calculate balances between users
- Track who owes whom
- Handle settlements
-
Transaction Management:
- Record transactions
- Track payment status
- Generate balance reports
- Fields: List users, List groups, List expenses
- Methods:
- addUser()
- createGroup()
- addExpense()
- getBalance()
- settleExpense()
- Fields: String id, String name, String email, Map<User, Double> balances
- Methods:
- updateProfile()
- getBalance()
- addBalance()
- subtractBalance()
- Fields: String id, String name, List members, List expenses
- Methods:
- addMember()
- removeMember()
- addExpense()
- getBalances()
- Fields: String id, String description, double amount, User paidBy, List paidFor, SplitType splitType
- Methods:
- calculateSplits()
- getAmount()
- getPaidBy()
- Fields: String id, User from, User to, double amount
- Methods:
- execute()
- getStatus()
- Values: EQUAL, EXACT, PERCENTAGE
SplitwiseService service = new SplitwiseService();
// Create users
User user1 = service.addUser("John", "john@example.com");
User user2 = service.addUser("Jane", "jane@example.com");
// Create a group
Group group = service.createGroup("Trip to Paris");
group.addMember(user1);
group.addMember(user2);
// Add an expense
Expense expense = service.addExpense(
"Dinner",
100.0,
user1,
Arrays.asList(user1, user2),
SplitType.EQUAL
);
// Get balances
double balance = service.getBalance(user1, user2);
// Settle expense
service.settleExpense(user2, user1, 50.0);See SplitwiseDemo.java for a sample usage and simulation of the Splitwise system.
- Add expense categories: Categorize expenses (food, travel, etc.)
- Add recurring expenses: Support for regular payments
- Add expense comments: Allow users to add notes to expenses
- Add expense attachments: Support for receipts and documents
- Add payment integration: Integrate with payment gateways
- Add notification system: Send reminders for pending payments
- Singleton Pattern: For the Splitwise service instance
- Factory Pattern: For creating different types of splits
- Strategy Pattern: For different expense splitting strategies
- Observer Pattern: For balance updates and notifications
- InvalidAmountException: Thrown when expense amount is invalid
- InvalidSplitException: Thrown when split details are invalid
- UserNotFoundException: Thrown when user is not found
- GroupNotFoundException: Thrown when group is not found
- InsufficientBalanceException: Thrown when user has insufficient balance
