-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.gatomalvado</groupId> | ||
<artifactId>MachineCoding</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>RELEASE</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gatomalvado; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello world!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.gatomalvado.splitwise; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import com.gatomalvado.splitwise.model.Expense; | ||
import com.gatomalvado.splitwise.model.ExpenseType; | ||
import com.gatomalvado.splitwise.model.User; | ||
import com.gatomalvado.splitwise.orchestrator.ExpenseManager; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
ExpenseManager expenseManager = new ExpenseManager(); | ||
|
||
// create users | ||
User user1 = User.builder().userId("User1").build(); | ||
User user2 = User.builder().userId("User2").build(); | ||
User user3 = User.builder().userId("User3").build(); | ||
User user4 = User.builder().userId("User4").build(); | ||
|
||
// add user to the expense manager | ||
expenseManager.addUser(user1); | ||
expenseManager.addUser(user2); | ||
expenseManager.addUser(user3); | ||
expenseManager.addUser(user4); | ||
|
||
while(true){ | ||
String command = scanner.nextLine(); | ||
String[] commands = command.split(" "); | ||
String commandType = commands[0]; | ||
|
||
switch(commandType){ | ||
case "SHOW": | ||
if(commands.length == 2){ | ||
expenseManager.showBalanceForUser(commands[1]); | ||
} else { | ||
expenseManager.showBalance(); | ||
} | ||
case "EXPENSE": | ||
String userWhoPaid = commands[1]; | ||
int numberOfUsers = Integer.parseInt(commands[2]); | ||
String expenseType = commands[3 + numberOfUsers]; | ||
List<String> userInvolved = new ArrayList<>(); | ||
for(int i=3; i< 3+numberOfUsers; i++){ | ||
userInvolved.add(commands[i]); | ||
} | ||
Double amount = Double.parseDouble(commands[4+numberOfUsers]); | ||
Expense expense = null; | ||
switch(expenseType) { | ||
case "EQUAL": | ||
expense = Expense.builder() | ||
.expenseType(ExpenseType.EQUAL) | ||
.paidBy(userWhoPaid) | ||
.paidFor(userInvolved) | ||
.amount(amount) | ||
.build(); | ||
expenseManager.addExpense(expense); | ||
case "EXACT": | ||
List<Double> amounts = new ArrayList<>(); | ||
for(int i=5+numberOfUsers; i<commands.length; i++){ | ||
amounts.add(Double.parseDouble(commands[i])); | ||
} | ||
expense = Expense.builder() | ||
.expenseType(ExpenseType.EXACT) | ||
.paidBy(userWhoPaid) | ||
.paidFor(userInvolved) | ||
.amount(amount) | ||
.exactAmount(amounts) | ||
.build(); | ||
expenseManager.addExpense(expense); | ||
case "PERCENT": | ||
List<Double> percentages = new ArrayList<>(); | ||
for(int i=5+numberOfUsers; i<commands.length; i++){ | ||
percentages.add(Double.parseDouble(commands[i])); | ||
} | ||
expense = Expense.builder() | ||
.expenseType(ExpenseType.PERCENT) | ||
.paidBy(userWhoPaid) | ||
.paidFor(userInvolved) | ||
.amount(amount) | ||
.percentage(percentages) | ||
.build(); | ||
expenseManager.addExpense(expense); | ||
default: | ||
// throw exception | ||
System.out.println("Command not supported "); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} |