import java.util.*; // System.out.println(); public class banking { private class Ucet { String cisloUctu; double stav; Ucet(String cisloUctu, double stav) { this.cisloUctu = cisloUctu; this.stav = stav; } } void run() { Scanner sc = new Scanner(System.in); int initialAccounts = 0; TreeMap accounts; while(true) { initialAccounts = sc.nextInt(); if(initialAccounts > 0) { // System.out.println("vstup: " + initialAccounts); accounts = new TreeMap(); for(int index = 0; index < initialAccounts; index++) { String account = sc.next(); double amount = sc.nextDouble(); accounts.put(account, new Ucet(account, amount)); } boolean exit = false; while(true) { char operation = sc.next().charAt(0); if(operation == 'e') { exit = true; System.out.println("end"); System.out.println(); break; } if(operation == 'w') { String account = sc.next(); double amount = sc.nextDouble(); Ucet ucet = accounts.get(account); System.out.format("withdraw %.2f: ", amount); if(ucet == null) { System.out.print("no such account"); }else if(ucet.stav >= amount) { ucet.stav = ucet.stav - amount; System.out.print("ok"); } else { System.out.print("insufficient funds"); } System.out.println(); } if(operation == 'd') { String account = sc.next(); double amount = sc.nextDouble(); Ucet ucet = accounts.get(account); System.out.format("deposit %.2f: ", amount); if(ucet == null) { System.out.print("no such account"); }else { ucet.stav = ucet.stav + amount; System.out.print("ok"); } System.out.println(); } if(operation == 't') { String accountFrom = sc.next(); String accountTo = sc.next(); double amount = sc.nextDouble(); Ucet ucetOdkud = accounts.get(accountFrom); Ucet ucetKam = accounts.get(accountTo); System.out.format("transfer %.2f: ", amount); if(ucetOdkud == null || ucetKam == null) { System.out.print("no such account"); } else if(ucetOdkud == ucetKam) { System.out.print("same account"); } else if(ucetOdkud.stav >= amount) { ucetOdkud.stav = ucetOdkud.stav - amount; ucetKam.stav = ucetKam.stav + amount; if(accountFrom.charAt(accountFrom.length() - 1) != accountTo.charAt(accountTo.length() - 1)) { System.out.print("interbank"); } else { System.out.print("ok"); } } else { System.out.print("insufficient funds"); } System.out.println(); } if(operation == 'c') { String account = sc.next(); Ucet ucet = accounts.get(account); System.out.print("create: "); if(ucet == null) { accounts.put(account, new Ucet(account, 0.0)); System.out.print("ok"); } else { System.out.print("already exists"); } System.out.println(); } if(operation == 'e') { exit = true; break; } } if(exit) { exit = false; continue; } } else { System.out.println("goodbye"); break; } } } public static void main(String[] args) { new banking().run(); } }