예제 #1
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;
  }
예제 #2
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;
  }
예제 #3
0
  public void printAllAccounts(String customerID) {
    // Sorts the customer based on ID, then prints the accounts information

    // change the withdrawal funcitons and deposit functions too
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    Collections.sort(cust, Customer.CompareIDs);
    String searchString = ajf.getCustomerID();

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);
    for (Customer customer : cust) {
      String id = customer.returnID();
      String name = customer.getName().toUpperCase();
      String pin = customer.returnPin();
      if (searchString.equals(id)) {
        ArrayList<Account> accounts = customer.getAccounts();
        if (!accounts.isEmpty()) {
          for (Account account : accounts) {
            if (account.checkActive()) {
              String accountNumber = account.returnNumber();
              double balance = account.returnBalance();
              String balanceAsString = formatter.format(balance);
              String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
              stringResults.append(customerInfo);
            }
          }
        }
      }
    }
    String resultsAsString = stringResults.toString();
    ajf.printInfo(resultsAsString);
  }
예제 #4
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;
  }
예제 #5
0
  public static ArrayList<Reservation> getReservations(Show[] shows, Customer[] customers) {
    Logger.log("Database.getReservations");
    ArrayList<Reservation> reservations = new ArrayList<Reservation>();
    try {
      ArrayList<Reservation> tempReservations = new ArrayList<Reservation>();
      Show show = null;
      Customer customer = null;

      ResultSet rs = query("SELECT COUNT(*) FROM reservation");
      rs.next();

      rs = query("SELECT * FROM reservation");
      while (rs.next()) {
        ArrayList<Point> position = new ArrayList<Point>();
        for (Show s : shows) {
          if (s.getID() == rs.getInt("forestilling_id")) {
            show = s;
          }
        }
        position.add(new Point(rs.getInt("pos_x"), rs.getInt("pos_y")));
        for (Customer c : customers) {
          if (c.getID() == rs.getInt("kunde_id")) {
            customer = c;
          }
        }
        tempReservations.add(
            new Reservation(show, position, customer, rs.getInt("reservation_id")));
      }
      // Merge all reservations which have the same show AND customer and save them in reservations
      // list
      while (tempReservations.size() != 0) {
        Customer cus = tempReservations.get(0).getCustomer();
        Show s = tempReservations.get(0).getShow();
        ArrayList<Point> seats = new ArrayList<Point>();
        int ID = tempReservations.get(0).getID();
        for (int x = 0; x < tempReservations.size(); x++) {
          if (tempReservations.get(x).getCustomer() == cus
              && tempReservations.get(x).getShow() == s) {
            seats.add(tempReservations.get(x).getFirstPos());
            tempReservations.remove(tempReservations.get(x));
            // After deleting the object, decrease x with 1 (else one element would never be
            // reached)
            x--;
          }
        }
        reservations.add(new Reservation(s, seats, cus, ID));
      }

    } catch (SQLException exception) {
      Logger.log(exception, "Database:getReservations");
    }
    Logger.log("Database.getReservations");
    return reservations;
  }
예제 #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 model_printAllAccounts() {
   ArrayList<String> cusIDs = new ArrayList<String>(100);
   cusIDs.add("Accounts:");
   Collections.sort(cust, Customer.CompareIDs);
   for (Customer c : cust) {
     String id = c.returnID();
     cusIDs.add(id);
   }
   if (ajf != null) {
     ajf.dispose();
   }
   ajf = new AdminRunningFrame(this);
   ajf.showOneCustomerScreen(cusIDs);
 }
예제 #8
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);
 }
예제 #9
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);
   }
 }
예제 #10
0
  public String close_account(String accountNum) {
    // actually closes the customer's account and returns a dialog box
    customer.removeAccount(accountNum);
    String cusInfo = customer.returnInfo();

    StringBuilder result = new StringBuilder();
    result.append("<html>Deleted account!<br>Updated information:<br>");
    String subCusInfo =
        cusInfo.substring(7, cusInfo.length()); // removes the last html tag from returnInfo()
    result.append(subCusInfo);
    try {
      saveFile(cust, DBfile);
    } catch (IOException e) {
      e.printStackTrace();
    }
    customer = null; // resets the customer and account after each transaction
    pin = null;
    return result.toString();
  }
예제 #11
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);
   }
 }
예제 #12
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;
  }
예제 #13
0
  public void printByCustomerName() {
    // Prints the database info by customer's name in ascending order
    Collections.sort(cust, Customer.CompareName);
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);

    if (!cust.isEmpty()) {
      for (Customer customer : cust) {
        String id = customer.returnID();
        String name = customer.getName().toUpperCase();
        String pin = customer.returnPin();
        ArrayList<Account> accounts = customer.getAccounts();
        if (!accounts.isEmpty()) {
          for (Account account : accounts) {
            if (account.checkActive()) {
              String accountNumber = account.returnNumber();
              double balance = account.returnBalance();
              String balanceAsString = formatter.format(balance);
              String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
              stringResults.append(customerInfo);
            }
          }

        } else {
          // Still prints customers who have created customer accounts but not set up any
          // checking/savings
          String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin);
          stringResults.append(noAccounts);
        }
      }
    }
    String resultsAsString = stringResults.toString();
    ajf.printInfo(resultsAsString);
  }
예제 #14
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
      }
    }
  }
예제 #15
0
 public void add_interest() {
   if ((transaction_counter % 5) == 0) {
     for (Customer c : cust) {
       ArrayList<Tuple> accountsAddedTo = new ArrayList<>(100);
       accountsAddedTo = c.addInterestToSavings(interest_rate);
       timestamp = date.getTime();
       if (!accountsAddedTo.isEmpty()) {
         String customerID = c.returnID();
         for (Tuple tuple : accountsAddedTo) {
           String accountNumber = tuple.getFirst();
           double logAmount = tuple.getSecond();
           AdminLog newTransaction =
               new AdminLog(timestamp, transaction_counter, customerID, accountNumber, logAmount);
           adminLogs.add(newTransaction);
         }
       }
       try {
         saveFile(cust, DBfile);
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
 }
예제 #16
0
  public void printHighestBalance() {
    // prints the accounts from highest amount to lowest, with those who have empty accounts last
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);

    if (!cust.isEmpty()) {
      ArrayList<Account> allAccounts = new ArrayList<Account>();
      ArrayList<Customer> CustomersNoAccounts = new ArrayList<Customer>();
      for (Customer c : cust) {
        ArrayList<Account> accounts = c.getAccounts();
        if (!accounts.isEmpty()) {
          // Concatenates all the accounts together for easy sorting
          allAccounts.addAll(accounts);
        }
        // Adds customers without accounts to a separate list to be printed at the end of all the
        // others
        else {
          CustomersNoAccounts.add(c);
        }
      }
      if (!allAccounts.isEmpty()) {
        Collections.sort(allAccounts, Account.CompareBalances);
        for (Account a : allAccounts) {
          if (a.checkActive()) {
            String id = a.getID();
            String name = a.getName().toUpperCase();
            String pin = a.getPin();
            String accountNumber = a.returnNumber();
            double balance = a.returnBalance();
            String balanceAsString = formatter.format(balance);
            String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
            stringResults.append(customerInfo);
          }
        }
      }
      if (!CustomersNoAccounts.isEmpty()) {
        Collections.sort(CustomersNoAccounts, Customer.CompareName);
        for (Customer c : CustomersNoAccounts) {
          String id = c.returnID();
          String name = c.getName().toUpperCase();
          String pin = c.returnPin();
          String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin);
          stringResults.append(noAccounts);
        }
      }
      String resultsAsString = stringResults.toString();
      ajf.printInfo(resultsAsString);
    }
  }
예제 #17
0
 public static boolean createReservation(Show show, Point[] points, Customer c) {
   Logger.log("Database.createReservation");
   String sql = "";
   for (Point seat : points) {
     sql =
         "INSERT INTO reservation(forestilling_id, pos_x, pos_y, kunde_id) VALUES ("
             + show.getID()
             + ","
             + seat.x
             + ","
             + seat.y
             + ","
             + c.getID()
             + ");";
     if (update(sql)) {
       continue;
     }
     return false;
   }
   Logger.log("Database.createReservation");
   return true;
 }
예제 #18
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;
  }