Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitwise #4

Open
dhilipD opened this issue Nov 10, 2021 · 0 comments
Open

Splitwise #4

dhilipD opened this issue Nov 10, 2021 · 0 comments

Comments

@dhilipD
Copy link

dhilipD commented Nov 10, 2021

package com.workattech.splitwise;

public class ExpenseService {
public static Expense createExpense(ExpenseType expenseType, double amount, User paidBy, List splits, ExpenseMetadata expenseMetadata) {
switch (expenseType) {
case EXACT:
return new ExactExpense(amount, paidBy, splits, expenseMetadata);
case PERCENT:
for (Split split : splits) {
PercentSplit percentSplit = (PercentSplit) split;
split.setAmount((amountpercentSplit.getPercent())/100.0);
}
return new PercentExpense(amount, paidBy, splits, expenseMetadata);
case EQUAL:
int totalSplits = splits.size();
double splitAmount = ((double) Math.round(amount
100/totalSplits))/100.0;
for (Split split : splits) {Splitwise
split.setAmount(splitAmount);
}
splits.get(0).setAmount(splitAmount + (amount - splitAmount*totalSplits));
return new EqualExpense(amount, paidBy, splits, expenseMetadata);
default:
return null;
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant