Пример #1
1
 void sortTransactionByDate() {
   List<Transaction> tr = new ArrayList<Transaction>(transactions.values());
   tr.sort(Transaction.DateComparator);
   for (Transaction t : tr) {
     t.displayTransaction();
   }
 }
Пример #2
0
 void editTransaction() {
   System.out.println("Enter the transaction Id to be Edit");
   Scanner in = new Scanner(System.in);
   int tid = in.nextInt();
   for (Transaction t : transactions.values()) {
     if (tid == t.getTransactionId()) {
       t.editTransaction();
     }
   }
 }
Пример #3
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());
   }
 }
Пример #4
0
  void transactionBetween() {
    Scanner in = new Scanner(System.in);
    Date after;
    Date before;
    String expectedPattern = "MM/dd/yyyy";
    SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
    try { // (2) give the formatter a String that matches the SimpleDateFormat pattern
      System.out.println("Enter Account Number");
      int acc = in.nextInt();
      boolean search = false;
      Customer cust = null;
      for (Customer c : customers.values()) {
        if (c.AccountId == acc) {
          search = true;
          cust = c;
        }
      }
      if (!search) {
        System.out.println("Account Not Found");
        return;
      }
      System.out.println("Enter Starting Date in MM/dd/yyyy format");
      String userInput = in.next();
      after = formatter.parse(userInput);
      System.out.println("Enter Starting Date in MM/dd/yyyy format");
      userInput = in.next();
      before = formatter.parse(userInput);
      for (int t : cust.TransactionId) {
        Transaction trans = transactions.get(t);
        if (trans.getDt().after(before) && trans.getDt().before(after)) trans.displayTransaction();
      }

    } catch (Exception e) {
      System.out.println(e.toString());
    }
  }