Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions splitwise/Balance.java
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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better names?

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;
}

}
39 changes: 39 additions & 0 deletions splitwise/Equal.java
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){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better variable name?
users?


User PaidByUSer = l1.get(0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public void split(List users) {
User paidByUser = users.get(0);

double divamount = getAmount()/l1.size();
Copy link
Copy Markdown
Collaborator

@gcnit gcnit Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase: divAmount

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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);

}



}
52 changes: 52 additions & 0 deletions splitwise/Exact.java
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));
}

}
}
}
36 changes: 36 additions & 0 deletions splitwise/ExpenseType.java
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;
}
}
48 changes: 48 additions & 0 deletions splitwise/Percentage.java
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);
}


}
Loading