import java.util.*; import java.io.*; class account{ String jmeno; double balance; public account(String jmeno) { this.jmeno = jmeno; this.balance = 0; } public account(String jmeno, double amountDeposit) { this.jmeno = jmeno; this.balance = amountDeposit; } public void setJmeno(String jmeno) { this.jmeno = jmeno; } public void setBalance(double balance) { this.balance = balance; } public String getJmeno() { return this.jmeno; } public double getBalance() { return this.balance; } } class banking { static ArrayList accounts = new ArrayList(); public static account searchFor( String jmeno) { for(int i=0 ; i < accounts.size(); i++ ) { account acc = accounts.get(i); if( jmeno.equals(acc.getJmeno())) return acc; } return null; } public static void create(String jmeno, double amountDeposit) { if( searchFor(jmeno) == null) { accounts.add( new account(jmeno, amountDeposit)); } } public static void create(String jmeno) { if( searchFor(jmeno) == null) { accounts.add( new account(jmeno)); System.out.println("create: ok"); } else{ System.out.println("create: already exists"); } } public static void deposit(String jmeno, double amountDeposit) { account acc = searchFor(jmeno); if( acc != null) { acc.setBalance(acc.getBalance() + amountDeposit); System.out.println(String.format("deposit %.2f", new Double(amountDeposit)) +": ok"); } else { System.out.println(String.format("deposit %.2f", new Double(amountDeposit)) +": no such account"); } } public static void withDraw(String jmeno, double amountWithdraw ) { account acc = searchFor(jmeno); if( acc != null) { double actualBalance; actualBalance = acc.getBalance(); if(actualBalance < amountWithdraw) { System.out.println(String.format("withdraw %.2f", new Double(amountWithdraw)) +": insufficient funds"); } else { actualBalance = actualBalance - amountWithdraw; acc.setBalance(actualBalance); System.out.println(String.format("withdraw %.2f", new Double(amountWithdraw)) +": ok"); } } else { System.out.println(String.format("withdraw %.2f", new Double(amountWithdraw)) +": no such account"); } } public static void transfer(String sourceAccount, String targetAccount, double amount) { account sourceAcc = searchFor(sourceAccount); account targetAcc = searchFor(targetAccount); if( sourceAcc == null || targetAcc == null){ System.out.println(String.format("transfer %.2f", new Double(amount)) +": no such account"); } else { if (sourceAcc.getJmeno().equals(targetAcc.getJmeno()) ) { System.out.println(String.format("transfer %.2f", new Double(amount)) +": same account"); } else { double acb = sourceAcc.getBalance(); if(acb >= amount ) { sourceAcc.setBalance(acb-amount); targetAcc.setBalance(targetAcc.getBalance()+amount); int iSource = sourceAccount.lastIndexOf('/') ; int iTarget = targetAccount.lastIndexOf('/') ; if( iSource > 0 && iTarget > 0 ) { String strSource = sourceAccount.substring(iSource); String strTarget = targetAccount.substring(iTarget); if( strSource.equals(strTarget) ) System.out.println(String.format("transfer %.2f", new Double(amount)) + ": interbank"); else System.out.println(String.format("transfer %.2f", new Double(amount)) + ": ok"); } } else { System.out.println(String.format("transfer %.2f", new Double(amount)) +": insufficient funds"); } } } } public static void main(String arg[]) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while( true ) { try { int n = Integer.parseInt(in.readLine()); if( n == 0 ) { System.out.println("goodbye"); return; } for(int j = 0; j < n; ++j ) { ArrayList commands = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(in.readLine(), " \t"); while( tokenizer.hasMoreTokens() ) commands.add(tokenizer.nextToken()); int iCommandCount = commands.size(); if( iCommandCount == 2 ) { String strLine = commands.get(0); create(strLine, Double.parseDouble(commands.get(1))); } } // for boolean bEnd = false; while( !bEnd ) { ArrayList commands = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(in.readLine(), " \t"); while( tokenizer.hasMoreTokens() ) commands.add(tokenizer.nextToken()); int iCommandCount = commands.size(); if( iCommandCount == 1 ) { if( commands.get(0).equals("end") ) { System.out.println("end\n"); bEnd = true; } } else { if( iCommandCount == 2 ) { String strLine = commands.get(0); if( strLine.equals("create") ) { create(commands.get(1)); } } if( iCommandCount == 3 ) { String strCommand = commands.get(0); if( strCommand.equals("withdraw") ) withDraw(commands.get(1), Double.parseDouble(commands.get(2))); else if( strCommand.equals("deposit") ) deposit(commands.get(1), Double.parseDouble(commands.get(2))); } else if( iCommandCount == 4 ) { String strCommand = commands.get(0); if( strCommand.equals("transfer") ) transfer(commands.get(1), commands.get(2),Double.parseDouble(commands.get(3))); } } } // while(!bEnd) } catch(Exception e) { } } // while(true) } }