Пример #1
0
  public void withdraw(String withdrawAmount, String accountNum) {
    // actually performs the withdrawal service
    double withdrawal = Double.parseDouble(withdrawAmount);
    boolean accountFound = customer.removeMoney(withdrawal, accountNum);
    if (accountFound == true) {
      // creates the log file
      double logAmount = -withdrawal;
      timestamp = date.getTime();
      String customerID = customer.returnID();
      AdminLog newTransaction =
          new AdminLog(timestamp, transaction_counter, customerID, accountNum, logAmount);
      adminLogs.add(newTransaction);

      transaction_counter++;
      add_interest();
      String infoMessage = customer.builderToString();
      jf.displayInfo(infoMessage);

      try {
        saveFile(cust, DBfile);
        saveFile(adminLogs, logFile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      jf.errorMessage(
          "We cannot find that account number in our database"); // pops up an error message if the
                                                                 // account was not found
    }
    customer = null; // resets the customer and account after each transaction
    pin = null;
  }
Пример #2
0
  public void deposit(String accountNum, String depositAmount) {
    // actually deposits the appropriate amount into the account

    double deposit =
        Double.parseDouble(
            depositAmount); // the balance in the Account class is saved as a double so it must be
                            // converted here
    boolean accountFound = customer.addMoney(deposit, accountNum);

    if (accountFound == true) {
      // create the log file
      timestamp = date.getTime();
      String customerID = customer.returnID();
      AdminLog newTransaction =
          new AdminLog(timestamp, transaction_counter, customerID, accountNum, deposit);
      adminLogs.add(newTransaction);

      transaction_counter++;
      add_interest();
      String infoMessage = customer.builderToString();
      jf.displayInfo(infoMessage);
      try {
        saveFile(cust, DBfile);
        saveFile(adminLogs, logFile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      jf.errorMessage(
          "We cannot find that account number in our database"); // pops up an error message if the
                                                                 // account was not found
    }
    customer = null; // resets the customer and account after each transaction
    pin = null;
  }
Пример #3
0
 public void model_open_account(String customerID, String customerPIN) {
   // calls the openAccountScreen function in RunningFrame class
   validate_info(customerID, customerPIN);
   if (customer != null) {
     jf.dispose();
     jf = new RunningFrame(this);
     jf.openAccountScreen();
   }
 }
Пример #4
0
 public void model_close_account(String customerID, String customerPIN) {
   // calls the transfer screen from the RunningFrame class
   validate_info(customerID, customerPIN);
   if (customer != null) {
     jf.dispose();
     jf = new RunningFrame(this);
     ArrayList<String> allAccounts = customer.getAllAccounts();
     jf.closeAccountScreen(allAccounts);
   }
 }
Пример #5
0
 public void model_account_info(String customerID, String customerPIN) {
   // calls the transfer screen from the RunningFrame class
   validate_info(customerID, customerPIN);
   if (customer != null) {
     jf.dispose();
     jf = new RunningFrame(this);
     String text = customer.printAccountInfo();
     jf.accountInfoScreen(text, adminLogs, customerID);
   }
 }
Пример #6
0
 public void model_transfer(String customerID, String customerPIN) {
   // calls the transfer screen from the RunningFrame class
   validate_info(customerID, customerPIN);
   if (customer != null) {
     jf.dispose();
     jf = new RunningFrame(this);
     String result = customer.returnInfo();
     ArrayList<String> allAccounts = customer.getAllAccounts();
     jf.transferScreen(result, allAccounts);
   }
 }
Пример #7
0
 public void callStartPage() {
   customer = null;
   pin = null;
   if (ajf != null) {
     ajf.dispose();
   }
   if (jf != null) {
     jf.dispose();
   }
   jf = new RunningFrame(this);
   jf.startPage();
 }
Пример #8
0
  public void open_account(boolean save) {
    // actually opens the account
    customer.addAccount(
        starting_account_number,
        save); // addAccount will create a new account based on whether it is savings/checkings

    StringBuilder text = new StringBuilder();
    text.append("<html>Account created!<br>");
    String result = customer.returnInfo();
    String subResult = result.substring(6);
    text.append(subResult);
    String infoText = text.toString();
    jf.displayInfo(infoText);

    transaction_counter++;
    add_interest();
    try {
      saveFile(cust, DBfile);
      saveFile(adminLogs, logFile);
    } catch (IOException e) {
      e.printStackTrace();
    }
    customer = null; // resets the customer and account after each transaction
    pin = null;
  }
Пример #9
0
 public void model_admin() {
   if (ajf != null) {
     ajf.dispose();
   }
   if (jf != null) {
     jf.dispose();
   }
   ajf = new AdminRunningFrame(this);
   ajf.startPage();
   if (DBfile.exists()) {
     try {
       cust = returnSavedData("p2.dat");
       if (cust.isEmpty()) {
         ajf.errorMessage("There are no customers in this database.");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
   if (logFile.exists()) {
     try {
       adminLogs = returnLog("p2.log");
       if (adminLogs.isEmpty()) {
         ajf.errorMessage("No entries have been found!");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
 }
Пример #10
0
  public void transfer(String transferAmount, String accountFrom, String accountTo) {
    // actually transfers the model
    double transferDouble = Double.parseDouble(transferAmount);
    boolean accountFromFound = customer.removeMoney(transferDouble, accountFrom);
    boolean accountToFound = customer.addMoney(transferDouble, accountTo);
    if (accountFromFound == true && accountToFound == true) {
      // creates the log file
      double logAmount = -transferDouble;
      timestamp = date.getTime();
      String customerID = customer.returnID();

      AdminLog firstTransaction =
          new AdminLog(timestamp, transaction_counter, customerID, accountFrom, transferDouble);

      timestamp = date.getTime();
      AdminLog secondTransaction =
          new AdminLog(timestamp, transaction_counter, customerID, accountTo, logAmount);
      adminLogs.add(firstTransaction);
      adminLogs.add(secondTransaction);

      for (AdminLog a : adminLogs) {
        long timestampe = a.getTimestamp();
      }

      transaction_counter++;
      add_interest();
      String infoMessage = customer.transferMessage(accountFrom, accountTo, transferDouble);
      jf.displayInfo(infoMessage);
      try {
        saveFile(cust, DBfile);
        saveFile(adminLogs, logFile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      jf.errorMessage(
          "We cannot find that account number in our database"); // pops up an error message if the
                                                                 // account was not found
    }
    customer = null; // resets the customer and account after each transaction
    pin = null;
  }
Пример #11
0
 public void create_account(String name, String newPin) {
   // Actually creates the customer account
   Customer customer = new Customer(starting_customer_number, newPin, name);
   cust.add(customer);
   String newCusID = customer.returnID();
   String idString = String.format("Your new Customer ID is: %s\n", newCusID);
   transaction_counter++;
   add_interest();
   try {
     saveFile(cust, DBfile);
   } catch (IOException e) {
     e.printStackTrace();
   }
   jf.displayInfo(idString);
 }
Пример #12
0
  private void validate_info(String newUserID, String newPin) {
    // validates that the customer has put in the correct Customer name and PIN
    if (newPin == null || newPin.length() != 4) {
      // returns the Customer object right away if the pin number is wrong, which will cause
      // the functions defined below to just pass through without doing anything
      pin = newPin;
    } else {
      // Validate user information
      for (Customer c : cust) {
        // Checks to see if the customer is already in the database
        String possibleCustID = c.returnID();

        if (possibleCustID.equals(newUserID)) {
          found = true;
          String possibleCustPIN = c.returnPin(); // Sets possible customer PIN for validation
          if (possibleCustPIN.equals(newPin)) {
            customer = c;
            pin = newPin;
          }
          pin =
              newPin; // so if customer ends up being null but the pin still has value, then the pin
                      // was incorrect
        }
      }
    }

    if (!found) { // calls the correct warning message if  either the customer or pin is not correct
      if (pin == null) {
        jf.errorMessage("That customer is not in our database.");
      } else {
        jf.errorMessage(
            "Invalid PIN number."); // if the customer has not been found but the pin has been set
                                    // that means the pin was invalid
      }
    }
  }
Пример #13
0
 public void model_create_account() {
   jf.dispose();
   jf = new RunningFrame(this);
   jf.createAccountScreen();
 }