Пример #1
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;
  }
Пример #2
0
  public void printTimeStamp() {
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    // creates a new header
    String Tim = "[Time Stamp]";
    String transID = "[Transaction ID]";
    String CusID = "[ID #]";
    String CusAcct = "[Account #]";
    String transAmount = "[Amount]";
    String header =
        String.format("%-30s %-20s %-10s %10s %10s\n", Tim, transID, CusID, CusAcct, transAmount);
    stringResults.append(header);

    if (cust.isEmpty()) {
      ajf.errorMessage("There are no customers in this database.");
    }

    if (adminLogs.isEmpty()) {

      ajf.errorMessage("No entries have been found!");
    } else {
      Collections.sort(adminLogs, AdminLog.CompareTimeStamp);
      for (AdminLog a : adminLogs) {
        long timestamp = a.getTimestamp();
        String date = dateFormat.format(timestamp);
        int transactionID = a.getTransactionID();
        String customerID = a.getCustomerID();
        String accountID = a.getAccountNum();
        double amount = a.getAmount();
        String newLine =
            String.format(
                "%-30s %-20d %-10s %10s %10s\n",
                date, transactionID, customerID, accountID, amount);
        stringResults.append(newLine);
      }
      String resultsAsString = stringResults.toString();
      ajf.printInfo(resultsAsString);
    }
  }
Пример #3
0
  public Atm() // constructor
        // sets the customer array to that found in the file if the file exists
      {
    try {
      // Set cross-platform Java L&F (also called "Metal")
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    if (logFile.exists()) {
      try {
        adminLogs = returnLog("p2.log");
        if (!adminLogs.isEmpty()) {
          // there may be customer data but perhaps no transactions yet.
          ArrayList<Integer> allTransactions = new ArrayList<>(100);
          for (AdminLog a : adminLogs) {

            int transaction = a.getTransactionID();
            ;
            allTransactions.add(transaction);
          }
          transaction_counter = Collections.max(allTransactions) + 1;
        }
      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    }

    if (DBfile.exists()) {
      try {

        cust = returnSavedData("p2.dat");

        // sets the starting ID to the max of all the IDs stored in the file.
        allIDs = new ArrayList<Integer>(100);
        ArrayList<Integer> allAccounts = new ArrayList<>();
        for (Customer customer : cust) {
          String idString = customer.returnID();
          int id = Integer.parseInt(idString);
          allIDs.add(id);
          int accountNumber = customer.returnMaxAccount();
          allAccounts.add(accountNumber);
        }
        // checks to see if the customer has even made any accounts, if not, max accounts will be
        // set at 1001
        if (starting_account_number != 1) {
          starting_account_number = Collections.max(allAccounts) + 1;
        }
        starting_customer_number = Collections.max(allIDs) + 1;

      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    } else {
      cust = new ArrayList<>(100);
      // creates the file if it does not exist
      try {
        saveFile(cust, DBfile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    interest_rate = 5;
  }