Skip to content

Commit

Permalink
machine coding splitwise 2hrs
Browse files Browse the repository at this point in the history
  • Loading branch information
msdeep14 committed Feb 13, 2023
1 parent e236d94 commit edf385a
Show file tree
Hide file tree
Showing 35 changed files with 803 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LowLevelDesign/SplitwiseApplication/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions LowLevelDesign/SplitwiseApplication/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions LowLevelDesign/SplitwiseApplication/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions LowLevelDesign/SplitwiseApplication/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions LowLevelDesign/SplitwiseApplication/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions LowLevelDesign/SplitwiseApplication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Design a system that allows for the addition of expenses and split the sam among multiple users or within a group.

Mandatory Requirements:

Create a group. A group can contain two or more users.
Split expenses between users( they may not be a part of a group) or in a group.
The strategy of splitting the amount should be extensible. You can implement equal splitting.
Able to see the pending credit or pending debit in a group or between users. (Let's say between A and B who is going to pay which user and the amount)
Can view the transaction details ( All the expenses which got added) in a group or peer-to-peer.
Bonus points:

Simplify debts ( Let’s say A has to pay 30 to B, B has to pay 30 to C, then in simplify debt view, A has to pay 30 to C directly instead of B ).

Guidelines:

Use any IDE
Write a driver class for demo purposes. Which will execute all the commands in one place in the code and have test cases.
You can print the output in the console. Do not create any UI for the application.
Please prioritize code compilation, execution, and completion
Work on the expected output first and then add bonus features last.
Expectations:

Your code should cover all the mandatory functionalities explained above.
Your code should be executable and clean.
Your code should be properly refactored, and exceptions should be gracefully handled.
Please add any assumptions taken in a README file.
How will you be evaluated?

Code should be working.
Code readability and testability
Separation Of Concerns
Object-Oriented concepts.
Language proficiency.
Scalability
Test Coverage
Concurrency handling(Bonus Points)
11 changes: 11 additions & 0 deletions LowLevelDesign/SplitwiseApplication/SplitwiseApplication.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
62 changes: 62 additions & 0 deletions LowLevelDesign/SplitwiseApplication/src/Driver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import dao.SplitWiseBalanceManager;
import model.account.Group;
import model.account.User;
import model.expense.ExpenseType;
import model.split.EqualSplit;
import model.split.Split;
import service.GroupService;
import service.SplitWiseService;
import service.UserService;

import java.util.ArrayList;
import java.util.List;

public class Driver {
public static void main(String[] args) {
System.out.println("SplitWise Application!!!");

SplitWiseBalanceManager splitWiseBalanceManager = SplitWiseBalanceManager.getSplitWiseBalanceManagerInstance();
UserService userService = new UserService(splitWiseBalanceManager);
GroupService groupService = new GroupService(splitWiseBalanceManager);
SplitWiseService splitWiseService = new SplitWiseService(splitWiseBalanceManager);

//create users
User user1 = userService.addUser("Mandeep");
User user2 = userService.addUser("Sandeep");
User user3 = userService.addUser("Bob");
User user4 = userService.addUser("Alice");


//Create Expense 1
Split split1 = new EqualSplit(user1);
Split split2 = new EqualSplit(user2);
Split split3 = new EqualSplit(user3);
List<Split> splitListForExpense1 = new ArrayList<>(List.of(split1, split2, split3));
splitWiseService.addExpense(ExpenseType.EQUAL, 900, "Mandeep",
splitListForExpense1, "Expense Number 1",
List.of("Mandeep", "Sandeep","Bob"));

//Display balance for users
splitWiseService.showUserExpenses("Mandeep");
splitWiseService.showUserExpenses("Alice");
splitWiseService.showUserExpenses("Bob");

//group Expense

//create group
Group group1 = groupService.addGroup("MyTestGroup", List.of("Mandeep","Bob"),
"This group is created for testing");

splitWiseService.addExpense(ExpenseType.EQUAL, 900, "Mandeep",
splitListForExpense1, "Expense Number 1",
List.of("Mandeep", "Sandeep","Bob"), "MyTestGroup");

//Get Group Expense
splitWiseService.showGroupExpense("MyTestGroup");


//List all expenses
splitWiseService.showAllExpenses();

}
}
Loading

0 comments on commit edf385a

Please sign in to comment.