Friday, June 27, 2008

For Kajiri


/* Description: Program to get Withdrawl amount and then the denominations. please find the * the sepcifications and reques from kajiri at the introdution thread
*/
import java.io.*;
import java.util.*;
public class forKajiri{
double wamount = 0.0;
String[] alldenoms = new String[100];
int alldenomsindex=0;
forKajiri() { while (true) {
System.out.print("Enter the Amount to be withdrawn: ");
Scanner scan = new Scanner(System.in);
wamount=Double.parseDouble(scan.nextLine());
double tdamount = 0.0; alldenomsindex = 0;
while (wamount != tdamount) {
double wamount2=wamount;
System.out.println("Enter the denominations like : 100 X 2 , type Exit to leave ");
String temp = scan.nextLine();
if (temp.toLowerCase().indexOf("exit") > -1) break;
alldenoms[alldenomsindex] = temp;
double dtemp=CalculateAmount(temp.toLowerCase());
wamount2=wamount-tdamount;
tdamount += dtemp;
double dt=wamount2-dtemp;
alldenoms[alldenomsindex] += "=" + dtemp;
System.out.println("Balance WDRL will be: " + wamount2 + " - " + dtemp + " = " + dt);
alldenomsindex++;
}
System.out.println("--------------------");
System.out.println("WDRL Amount: " + wamount);
System.out.println("Denominations Total: " + tdamount);
for (int i = 0; i < alldenomsindex; i++)
System.out.println(alldenoms[i]);
System.out.println("--------------------");
System.out.println("To continue type Y or type anyother");
if (!scan.nextLine().toLowerCase().trim().equals("y")) break; }
}
public double CalculateAmount(String samount) {
if(samount.indexOf("*")>-1) samount=samount.replace('*','x');
return Double.parseDouble(samount.trim().split("x")[0])*Double.parseDouble(samount.trim().split("x")[1]);
}
public static void main(String args[]){ new forKajiri(); }
}