Ejemplo n.º 1
1
 void sortbyAccount() {
   List<Accounts> ac = new ArrayList<Accounts>(accounts.values());
   ac.sort(Accounts.AccountComparator);
   for (Accounts a : ac) {
     a.dispaly();
   }
 }
Ejemplo n.º 2
0
 void sortAccountByCustomer() {
   List<Customer> cl = new ArrayList<Customer>(customers.values());
   cl.sort(Customer.CustomerComparatorByName);
   for (Customer c : cl) {
     System.out.println("Customer Name: " + c.CustomerName);
     Accounts a = accounts.get(c.AccountId);
     a.dispaly();
   }
 }
Ejemplo n.º 3
0
 void searchAccountByBalance() {
   System.out.println(
       "\nEnter your Choice\n1.Exact Balance\n2.More than Balance\n3.Less than Balance\n4.Balance Range");
   Scanner in = new Scanner(System.in);
   int amount;
   int choice = in.nextInt();
   boolean flag = true;
   switch (choice) {
     case 1:
       System.out.println("Enter the Amount to be search");
       amount = in.nextInt();
       for (Accounts a : accounts.values()) {
         if (a.balance == amount) {
           a.dispaly();
           flag = false;
         }
       }
       if (flag) System.out.println("No Data Found");
       break;
     case 2:
       System.out.println("Enter the Amount to be search for equal and more");
       amount = in.nextInt();
       for (Accounts a : accounts.values()) {
         if (a.balance >= amount) {
           a.dispaly();
           flag = false;
         }
       }
       if (flag) System.out.println("No Data Found");
       break;
     case 3:
       System.out.println("Enter the Amount to be search for equal and less");
       amount = in.nextInt();
       for (Accounts a : accounts.values()) {
         if (a.balance <= amount) {
           a.dispaly();
           flag = false;
         }
       }
       if (flag) System.out.println("No Data Found");
       break;
     case 4:
       System.out.println("Enter the Amount range\nMinimum:");
       amount = in.nextInt();
       System.out.println("Maximum:");
       int max = in.nextInt();
       for (Accounts a : accounts.values()) {
         if (a.balance >= amount && a.balance <= max) {
           a.dispaly();
           flag = false;
         }
       }
       if (flag) System.out.println("No Data Found");
       break;
     default:
       System.out.println("Worn Input");
   }
 }
Ejemplo n.º 4
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());
   }
 }