Example #1
0
 // Now onwards code for Transaction management
 void addTransaction() throws CustomerIdInvalid, BalanceNotSufficient {
   try {
     LastTransNo++;
     Scanner in = new Scanner(System.in);
     System.out.println("Choose Type of Transaction\n1.Credit\n2.Debit");
     int choice = in.nextInt();
     if (choice == 1) {
       System.out.println("Enter Customer ID: ");
       int Cid = in.nextInt();
       Customer c = customers.get(Cid);
       if (c == null) throw new CustomerIdInvalid("Customer Not valid");
       System.out.println("Enter the Amount to be credit");
       int amount = in.nextInt();
       Accounts a = accounts.get(c.AccountId);
       a.balance = a.balance + amount;
       Transaction t = new CreditTransaction(LastTransNo, Cid, c.AccountId, amount);
       c.TransactionId.add(LastTransNo);
       transactions.put(LastTransNo, t);
       t.displayTransaction();
     }
     if (choice == 2) {
       System.out.println("Enter Customer Number");
       int Cid = in.nextInt();
       Customer c = customers.get(Cid);
       if (c == null) throw new CustomerIdInvalid("Customer Not valid");
       System.out.println("Enter the Amount to be Debit");
       int amount = in.nextInt();
       Accounts a = accounts.get(c.AccountId);
       if (a.balance >= amount) a.balance = a.balance - amount;
       else throw new BalanceNotSufficient("Balance is less");
       Transaction t = new DebitTransaction(LastTransNo, Cid, c.AccountId, amount);
       c.TransactionId.add(LastTransNo);
       transactions.put(LastTransNo, t);
       t.displayTransaction();
     }
   } catch (Exception e) {
     System.out.println(e.toString());
   }
 }
Example #2
0
 // Code For Account management
 void openAccount() throws CustomerIdInvalid {
   Accounts ac = null;
   Customer c = null;
   try {
     Scanner in = new Scanner(System.in);
     System.out.println("Choose Type of Account\n1.CheckIn\n2.Savings\n3.Business");
     int choice = in.nextInt();
     System.out.println("Enter Customer Name:");
     String name = in.next();
     System.out.println("Enter Customer Address:");
     String addr = in.next();
     LastCustNo++;
     LastAccNo++;
     switch (choice) {
       case 1:
         ac = new Checkin(LastCustNo, LastAccNo);
         accounts.put(LastAccNo, ac);
         c = new Customer(name, LastCustNo, addr, LastAccNo);
         customers.put(LastCustNo, c);
         break;
       case 2:
         ac = new Savings(LastCustNo, LastAccNo);
         accounts.put(LastAccNo, ac);
         c = new Customer(name, LastCustNo, addr, LastAccNo);
         customers.put(LastCustNo, c);
         break;
       case 3:
         ac = new Business(LastCustNo, LastAccNo);
         accounts.put(LastAccNo, ac);
         c = new Customer(name, LastCustNo, addr, LastAccNo);
         customers.put(LastCustNo, c);
         break;
       default:
         System.out.println("Worng Input");
         break;
     }
     System.out.println(
         "Thank You! "
             + name
             + "\nYour Customer ID is:"
             + LastCustNo
             + "\nAnd your Account Number is:"
             + LastAccNo
             + "\n\n");
   } catch (Exception e) {
     System.out.println("Unable to open Account");
   }
 }