diff --git a/Main.class b/Main.class new file mode 100644 index 0000000..3c098f1 Binary files /dev/null and b/Main.class differ diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..916a83f --- /dev/null +++ b/Main.java @@ -0,0 +1,378 @@ +/* Machine Coding of SplitWise by TUSHAR ANAND, KIIT DEEMED TO BE UNIVERISTY*/ + + +/* Importing Necessary Packages*/ + +import java.util.Random; +import java.util.*; +import java.io.*; +import java.lang.*; +public class Main +{ + /** + In this project we are maintaining a two dimensional matrix to keep the record of transaction between the users + The matrix is named as 'Matrix' and we will call it as Transaction Matrix. + **/ + + + /* + printTable() method print the Matrix of Transction done between the users. + It keep records from the begining meaning if there is no borrow between the users still we maintain the amount. + **/ + + public static void printTable(int Matrix[][]) + { + System.out.println(); + for(int i=1;iMatrix[j][i]) + { + System.out.println("User"+j+" owes "+"User"+i+": "+(Matrix[i][j]-Matrix[j][i])); + empty=true; + } + else if(Matrix[i][j]' command is given + It shows the complete description of particular user. + **/ + + public static void showUserTransactionTable(int [][] Matrix , String userId ) + { + int indexUser = Integer.parseInt(userId.substring(1)); /* Getting Payer's ID */ + + int net_amount=0; + boolean empty = false; /* Variable for checking if there is atleast one transaction otherwise + 'No Balances' will be displayed + */ + + for(int i=1;iMatrix[i][indexUser]) + { + System.out.println("User"+i+" owes "+"User"+indexUser+": "+(Matrix[indexUser][i]-Matrix[i][indexUser])); + empty=true; + } + else if(Matrix[indexUser][i] */ + { + String userId = words[1]; + showUserTransactionTable(Matrix,userId); + } + + else + { + /** + OTHER OPERATIONS LIKE: + 1) EXPENSE u1 1000 4 u1 u2 u3 u4 EQUAL + 2) EXPENSE u4 1200 4 u1 u2 u3 u4 PERCENT 40 20 20 20 + 3) EXPENSE u1 1250 2 u2 u3 EXACT 370 880 + + **/ + + int shareExact[]; /* Array to collect 'EXACT' */ + + int sharePercent[]; /* Array to collect 'EXACT' */ + + String payer = words[1]; /* user who pays the amount */ + + int amount = Integer.parseInt(words[2]); /* Amount of money paid */ + + int noUser=Integer.parseInt(words[3]); /* Number of user involved in the transction */ + + String userArr[] = new String[noUser]; /* Array of users involved Transction */ + + + int i=4; /* Because we will get users from 4th index */ + + for(i=4 ; i<4+noUser ;i++) + { + userArr[i-4]=words[i]; /* To put the elements in userArr from 0th index */ + } + + String type = words[i++]; /* Options Like : 'EQUAL' 'SHARE' 'EXACT' */ + + + if(type.equals("EQUAL")) + { + updateTransctionTableEqual(Matrix,payer, userArr,amount); + + } + + else if(type.equals("PERCENT")) + { + sharePercent=new int[noUser]; + + for(int k=0;k