-
Notifications
You must be signed in to change notification settings - Fork 83
Splitwise design #10
base: master
Are you sure you want to change the base?
Splitwise design #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package splitwise; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * | ||
| * @author rajeshkumar.yadav | ||
| */ | ||
| public class Balance { | ||
|
|
||
| Map<Integer, Double> pay; | ||
| Map<Integer, Double> getBack; | ||
|
|
||
| public Balance() { | ||
| pay = new HashMap<Integer, Double>(); | ||
| getBack = new HashMap<Integer, Double>(); | ||
| } | ||
|
|
||
| public Map<Integer, Double> getPay() { | ||
| return pay; | ||
| } | ||
|
|
||
| public void setPay(Map<Integer, Double> pay) { | ||
| this.pay = pay; | ||
| } | ||
|
|
||
| public Map<Integer, Double> getGetBack() { | ||
| return getBack; | ||
| } | ||
|
|
||
| public void setGetBack(Map<Integer, Double> getBack) { | ||
| this.getBack = getBack; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package splitwise; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * | ||
| * @author rajeshkumar.yadav | ||
| */ | ||
|
|
||
| public class Equal extends ExpenseType{ | ||
|
|
||
| public Equal(int amount) { | ||
| super(amount); | ||
| } | ||
|
|
||
| public void split(List<User> l1){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better variable name? |
||
|
|
||
| User PaidByUSer = l1.get(0); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public void split(List users) { |
||
| double divamount = getAmount()/l1.size(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase: divAmount
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or a better name? |
||
| l1.remove(0); | ||
| List<Double> amount = new ArrayList<>(); | ||
| for(int i=0; i<l1.size(); i++) | ||
| amount.add(divamount); | ||
|
|
||
| Exact ex = new Exact(); | ||
| ex.split(l1, amount, PaidByUSer); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package splitwise; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * | ||
| * @author rajeshkumar.yadav | ||
| */ | ||
| public class Exact extends ExpenseType{ | ||
|
|
||
| public Exact() { | ||
| super(0); | ||
| } | ||
|
|
||
| public void split(List<User> l1, List<Double> l2, User paidByUser){ | ||
|
|
||
| Balance paidByUserBalance = paidByUser.getBalance(); | ||
| int paidByUserId = paidByUser.getUseId(); | ||
|
|
||
| for(int i=0; i<l1.size(); i++) | ||
| { | ||
| Balance b = l1.get(i).getBalance(); | ||
| Map<Integer, Double> m = b.getPay(); | ||
|
|
||
| if(m.get(paidByUserId) != null) | ||
| { | ||
| m.put(paidByUserId, m.get(paidByUserId) + l2.get(i)); | ||
| }else | ||
| { | ||
| m.put(paidByUserId, l2.get(i)); | ||
| } | ||
|
|
||
| Map<Integer, Double> paidByUserGetBackMap = paidByUserBalance.getGetBack(); | ||
|
|
||
| if(paidByUserGetBackMap.get(l1.get(i).getUseId()) != null) | ||
| { | ||
| paidByUserGetBackMap.put(l1.get(i).getUseId(), paidByUserGetBackMap.get(l1.get(i).getUseId()) + l2.get(i)); | ||
|
|
||
| }else | ||
| { | ||
| paidByUserGetBackMap.put(l1.get(i).getUseId(), l2.get(i)); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package splitwise; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * | ||
| * @author rajeshkumar.yadav | ||
| */ | ||
| public class ExpenseType { | ||
|
|
||
| private int amount; | ||
| public void split(List<User> l1, List<Double> l2, User paidByUser){ | ||
|
|
||
| } | ||
| public void split(List<User> l1, List<Integer> l2){ | ||
| } | ||
| public void split(List<User> l1){ | ||
| } | ||
|
|
||
| public ExpenseType(int amount) { | ||
| this.amount = amount; | ||
| } | ||
|
|
||
| public int getAmount() { | ||
| return amount; | ||
| } | ||
|
|
||
| public void setAmount(int amount) { | ||
| this.amount = amount; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package splitwise; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * | ||
| * @author rajeshkumar.yadav | ||
| */ | ||
| public class Percentage extends ExpenseType{ | ||
|
|
||
| public Percentage(int amount) { | ||
| super(amount); | ||
| } | ||
|
|
||
| public void split(List<User> l1, List<Integer> l2){ | ||
|
|
||
| int sum = 0; | ||
| for(int i=0; i<l2.size(); i++) | ||
| { | ||
| sum = sum + l2.get(i); | ||
| } | ||
| if(sum != 100) | ||
| { | ||
| System.err.println("Not a proper percentage division "); | ||
| return; | ||
| } | ||
|
|
||
| List<Double> list1 = new ArrayList<Double>(); | ||
| for(int i=0; i<l2.size(); i++) | ||
| { | ||
| double d = (getAmount() * l2.get(i)) / 100; | ||
| list1.add(d); | ||
| } | ||
|
|
||
| User paidByUser = l1.get(0); | ||
| l1.remove(0); | ||
| Exact ex = new Exact(); | ||
| ex.split(l1, list1, paidByUser); | ||
| } | ||
|
|
||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better names?