Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.59 KB | None | 0 0
  1.  
  2. /**
  3.  * The menu class is where the main method is. This class controls the whole program
  4.  * (The interface of the program)
  5.  * @author (James Rogers)
  6.  * @version (v1)
  7.  */
  8.  
  9. import java.util.Scanner;
  10. import java.util.ArrayList;
  11.  
  12. public class Menu
  13.  
  14. {
  15.       //Instance Variables
  16.      // Ignore the 2 comments below (For testing)
  17.     // public ArrayList<String> custUsername = new ArrayList<String>(); //custUsername.add("add to array");
  18.    // public ArrayList<String>  custPassword = new ArrayList<String>();
  19.     Scanner keyboard = new Scanner(System.in);
  20.     Bank bank = new Bank();
  21.     boolean exit; // Set to false by deafult so no value to se is needed
  22.    
  23.     // Set console colours
  24.     public static final String ANSI_WHITE_BACKGROUND = "\u001B[47m"; // White Background
  25.     public static final String ANSI_BLUE = "\u001B[34m"; // Blue Text
  26.     public static final String ANSI_RESET = "\u001B[0m";
  27.  
  28.  
  29.     // This is where the program will start from Main Method
  30.     public static void main(String[] args) {
  31.         Menu menu = new Menu(); // Creating an object of this class
  32.         menu.runMenu(); // Need to tell the menu to run
  33.  
  34.     }
  35.  
  36.     // Run menu method
  37.     public void runMenu() {
  38.         printBanner();
  39.         while(!exit) { // While not exit so while exit is false
  40.             printMenu();
  41.             int choice = getInput();
  42.             performAction(choice);
  43.         }
  44.     }
  45.  
  46.     private void printBanner() {
  47.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "=============================" + ANSI_RESET);
  48.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "|         Welcome To        |" + ANSI_RESET);
  49.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "|          C.A.M.P          |" + ANSI_RESET);
  50.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "|  Created by James Rogers  |" + ANSI_RESET);
  51.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "=============================" + ANSI_RESET);
  52.  
  53.     }
  54.  
  55.     private void printMenu() {
  56.         displaySubHeader("Please choose an option");
  57.         System.out.println("(1) Customer Login - via your Username & Password");
  58.         System.out.println("(2) Admin Login");
  59.         System.out.println("(3) Application Help");
  60.         System.out.println("(0) Exit Application");
  61.     }
  62.     // Set to int as we are getting an integer
  63.     private int getInput() {
  64.         // Reads info from user input - Keyboard and then returns it to the int choice within the run menu method
  65.  
  66.         // Start with a try catch block - nesscary for validtion purposes
  67.         int choice = -1;
  68.         // Do while loop so it at least runs once time
  69.         do {
  70.             System.out.print("Enter your choice: ");
  71.             try {
  72.                 choice = Integer.parseInt(keyboard.nextLine());
  73.  
  74.             }
  75.             catch(NumberFormatException e) {
  76.                 System.out.println("Invalid slection - Please use numbers only");
  77.             }
  78.             if(choice <0 || choice > 3){
  79.                 System.out.println("Please select option 1,2,3 or 0 to Exit");
  80.             }
  81.  
  82.         }while(choice <0 || choice > 3);
  83.         return choice;
  84.     }
  85.  
  86.     private void performAction(int choice) {
  87.         switch(choice){
  88.             case 0:
  89.             System.out.println("Thanks for using C.A.M.P");
  90.             System.exit(0); // Standard way of exiting
  91.             break; // Need break otherwise it will fall through the other case
  92.             case 1:
  93.             LoginToAccount();
  94.             break;
  95.             case 2:
  96.             AdminLogin();
  97.             break;
  98.             case 3:
  99.             helpOptions();
  100.             break;
  101.             // Deafult case just in case - pardon the pun - we wont know what happend
  102.             default:
  103.             System.out.println("Unknown Error has occured");
  104.  
  105.         }
  106.     }
  107.    
  108.    
  109.     // Help Section Start
  110.     // On screen help method
  111.    
  112.     private void printHelpMenu() {
  113.         displaySubHeader("C.A.M.P Help System");
  114.         System.out.println("(1) How to control the application?");
  115.         System.out.println("(2) How to make a Deposit?");
  116.         System.out.println("(3) How to make a withdrawal?");
  117.         System.out.println("(4) How to make a transfer?");
  118.         System.out.println("(5) How to create an account (Admin)?");
  119.         System.out.println("(6) How to list accounts?");
  120.         System.out.println("(7) How to display account info?");
  121.         System.out.println("(8) How to display account balance?");
  122.         System.out.println("(9) How to exit the application?");
  123.         System.out.println("(0) Exit Help System >");
  124.     }
  125.    
  126.     private void helpOptions() {
  127.  
  128.         printHelpMenu();
  129.         int helpChoice = getHelpInput();
  130.         helpAction(helpChoice);
  131.  
  132.     }
  133.    
  134.     private int getHelpInput() {
  135.         // Reads info from user input - Keyboard and then returns it to the int choice within the run menu method
  136.  
  137.         // Start with a try catch block - nesscary for validtion purposes
  138.         int helpChoice = -1;
  139.         // Do while loop so it at least runs once time
  140.         do {
  141.             System.out.print("Enter your choice: ");
  142.             try {
  143.                 helpChoice = Integer.parseInt(keyboard.nextLine());
  144.  
  145.             }
  146.             catch(NumberFormatException e) {
  147.                 System.out.println("Invalid slection - Please use numbers only");
  148.             }
  149.             if(helpChoice <0 || helpChoice > 9){
  150.                 System.out.println("Please select options between 1 & 9");
  151.             }
  152.  
  153.         }while(helpChoice <0 || helpChoice > 9);
  154.         return helpChoice;
  155.     }
  156.  
  157.     private void helpAction(int helpChoice) {
  158.         switch(helpChoice){
  159.             case 1:
  160.             System.out.println("To navigate in CAMP use the numbers to choose your \n selection when asked simply type in 1,2,4 etc to complete your selection");
  161.             System.out.println();
  162.             helpOptions();
  163.             break;
  164.             case 2:
  165.             System.out.println("To make a deposit you first need to log in to your account. \n Once you are logged in select option 4. \n Then press enter, and enter the amount you would like to deposit. \n Then press enter again to deposit the amount.");
  166.             System.out.println();
  167.             helpOptions();
  168.             break;
  169.             case 3:
  170.             System.out.println("To make a withdrawal you need to be logged in. \n Once logged in select option 5. \n Once entered press enter and then enter the amount you wish to withdraw. \n Once your happy press enter.");
  171.             System.out.println();
  172.             helpOptions();
  173.             break;
  174.             case 4:
  175.             System.out.println("To make a transfer you need to be logged in. \n Once logged in select option 6. \n Once entered press enter, then select the account in which you want to transfer from. \n Once chosen press enter, then enter the amount you wish to transfer. \n Then press enter. Now choose the accout you wish to transfer the funds to once inputted press enter.");
  176.             System.out.println();
  177.             helpOptions();
  178.             break;
  179.             case 5:
  180.             System.out.println("Log in to the admin account. \n Then select option 1 and type either current, basic or savings and press enter. \n Then fill out the rest of the account creation process by simply entering data and then pressing enter once done");
  181.             System.out.println();
  182.             helpOptions();
  183.             break;
  184.             case 6:
  185.             System.out.println("To list accounts make sure your logged in. \n Once logged in select option 3 and press enter. \n All of the accounts will show.");
  186.             System.out.println();
  187.             helpOptions();
  188.             break;
  189.             case 7:
  190.             System.out.println("To display all account info first make sure your logged in. \n Then select option 2 and press enter. \n Then select the account in which you want to display the details.");
  191.             System.out.println();
  192.             helpOptions();
  193.             break;
  194.             case 8:
  195.             System.out.println("To show the balance of an account first  make sure your logged in. \n Select option 1 and press enter. Select the account in which you want to see the balance of. \n Press enter and the balance will be displayed");
  196.             System.out.println();
  197.             helpOptions();
  198.             break;
  199.             case 9:
  200.             System.out.println("To exit the application enter 0 and return when your on the main menu screen.");
  201.             System.out.println();
  202.             helpOptions();
  203.             break;
  204.             case 0:
  205.             System.out.println("Help System Closed");
  206.             break;
  207.             // Deafult case just in case - pardon the pun - we wont know what happend
  208.             default:
  209.             System.out.println("Unknown Error has occured");
  210.  
  211.         }
  212.     }
  213.    
  214.     // Help Section End
  215.    
  216.    
  217.    
  218.  
  219.     // Customer login method
  220.     public void LoginToAccount() {
  221.        
  222.        
  223.        
  224.         // Create array as we need to store more than 1 usernmane & password
  225.        
  226.          ArrayList<String> custUsername = Customer.usernameMainArray;
  227.          ArrayList<String> custPassword = Customer.passwordMainArray;
  228.          
  229.         //Hard code appending array values
  230.         //custUsername.add("james");
  231.         //custPassword.add("password");
  232.         boolean correctLogin = false;
  233.         //String username = custUsername;
  234.         //String password = custPassword;
  235.         String inputtedUsername;
  236.         String inputtedPassword;
  237.        
  238.            if (custUsername.isEmpty()) {
  239.                 System.out.println("No users/accounts have been created yet!");
  240.             } else {
  241.  
  242.         while(correctLogin != true){
  243.             //System.out.println(custUsername);
  244.             System.out.println();
  245.             System.out.println("Please enter your username: ");
  246.             inputtedUsername = keyboard.nextLine();
  247.  
  248.             System.out.println("Please enter your password: ");
  249.             inputtedPassword = keyboard.nextLine();
  250.  
  251.             if(custUsername.contains(inputtedUsername) && (custPassword.contains(inputtedPassword))) {
  252.                 System.out.println();
  253.                 System.out.println("Welcome: " + inputtedUsername);
  254.                 correctLogin = true;
  255.                 customerOptions();
  256.                 // No need for a break as the while loop will break anyway due to the change of the bool
  257.             } else {
  258.  
  259.                 System.out.println("Hmmm.. Your Login information was wrong, please try again");
  260.             }
  261.         }  
  262.       }
  263.         //Logged in area stop the Main Menu
  264.     }
  265.  
  266.     // Admin Login method
  267.     private void AdminLogin() {
  268.         boolean correctLogin = false;
  269.         String username = "Admin";
  270.         String password = "Big@Banker0";
  271.         String inputtedUsername;
  272.         String inputtedPassword;
  273.  
  274.         while(correctLogin != true) {
  275.             System.out.println();
  276.             System.out.println("Please enter your username: ");
  277.             inputtedUsername = keyboard.nextLine();
  278.  
  279.             System.out.println("Please enter your password: ");
  280.             inputtedPassword = keyboard.nextLine();
  281.  
  282.             if(inputtedUsername.equals(username)&& inputtedPassword.equals(password)){
  283.                 System.out.println();
  284.                 System.out.println("Welcome: " + username);
  285.                 correctLogin = true;
  286.                 adminOptions();
  287.                 // No need for a break as the while loop will break anyway due to the change of the bool            
  288.             } else {
  289.  
  290.                 System.out.println("Hmmm.. Your Login information was wrong, please try again");
  291.             }
  292.  
  293.         }
  294.     }
  295.  
  296.     private void customerOptions() {
  297.  
  298.         printCustomerMenu();
  299.         int customerChoice = getCustomerInput();
  300.         customerAction(customerChoice);
  301.  
  302.     }
  303.  
  304.     private void printCustomerMenu() {
  305.         System.out.println("Customer Options");
  306.         System.out.println("(1) Display Balance");
  307.         System.out.println("(2) Display Your Details");
  308.         System.out.println("(3) List Accounts");
  309.         System.out.println("(4) Make a Deposit");
  310.         System.out.println("(5) Make a Withdrawal");
  311.         System.out.println("(6) Make a Transfer");
  312.     }
  313.     // Set to int as we are getting an integer
  314.  
  315.     private int getCustomerInput() {
  316.         // Reads info from user input - Keyboard and then returns it to the int choice within the run menu method
  317.  
  318.         // Start with a try catch block - nesscary for validtion purposes
  319.         int customerChoice = -1;
  320.         // Do while loop so it at least runs once time
  321.         do {
  322.             System.out.print("Enter your choice: ");
  323.             try {
  324.                 customerChoice = Integer.parseInt(keyboard.nextLine());
  325.  
  326.             }
  327.             catch(NumberFormatException e) {
  328.                 System.out.println("Invalid slection - Please use numbers only");
  329.             }
  330.             if(customerChoice <0 || customerChoice > 6){
  331.                 System.out.println("Please select options between 1 & 6");
  332.             }
  333.  
  334.         }while(customerChoice <0 || customerChoice > 6);
  335.         return customerChoice;
  336.     }
  337.  
  338.     private void customerAction(int customerChoice) {
  339.         switch(customerChoice){
  340.             case 1:
  341.             displayBalance();
  342.             break;
  343.             case 2:
  344.             displayDetails();
  345.             break;
  346.             case 3:
  347.             listAccounts();
  348.             break;
  349.             case 4:
  350.             makeADeposit();
  351.             break;
  352.             case 5:
  353.             makeAWithdrawal();
  354.             break;
  355.             case 6:
  356.             makeATransfer();
  357.             break;
  358.             // Deafult case just in case - pardon the pun - we wont know what happend
  359.             default:
  360.             System.out.println("Unknown Error has occured");
  361.  
  362.         }
  363.     }
  364.  
  365.     private void displayBalance() {
  366.         displaySubHeader("Account Balance");
  367.         int account = selectAccount();
  368.         if (account >= 0 ) {
  369.             // Get balance by calling getBalance
  370.             System.out.println("Your balance is: £" + bank.getCustomer(account).getAccount().getBalance()); // Example of polymorphism aswell as list account details
  371.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  372.         }
  373.  
  374.     }
  375.  
  376.     private void displayDetails() {
  377.        displaySubHeader("Account Details");
  378.        int account = selectAccount();
  379.         if (account >= 0 ) {
  380.             System.out.println(bank.getCustomer(account).getAccount()); // Example of polymorphism aswell as list account details
  381.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  382.         }
  383.     }
  384.  
  385.     private void listAccounts() {
  386.         displaySubHeader("List Accounts");
  387.         ArrayList<Customer> customers = bank.getCustomers();
  388.         if (customers.size() <= 0){
  389.             System.out.println("No Customers found!!");
  390.            
  391.         }
  392.         System.out.println("Select an acccount:");
  393.         for(int i = 0; i < customers.size(); i++) {
  394.             System.out.println((i+1) + ") " + customers.get(i).basicInfo());
  395.         }      
  396.     }
  397.  
  398.     private void makeADeposit() {
  399.          displaySubHeader("Make a Deposit");
  400.         int account = selectAccount();
  401.         if (account >= 0 ) {
  402.             System.out.print("How much would you like to deposit?: ");
  403.             double amount = 0;
  404.             try {
  405.                 amount = Double.parseDouble(keyboard.nextLine());
  406.             }
  407.             catch(NumberFormatException e){
  408.                 amount = 0;
  409.             }
  410.             bank.getCustomer(account).getAccount().deposit(amount);
  411.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  412.         }
  413.  
  414.     }
  415.  
  416.     private void makeAWithdrawal() {
  417.         displaySubHeader("Make a Withdrawal");
  418.         int account = selectAccount();
  419.         if (account >= 0 ) {
  420.             System.out.print("How much would you like to withdraw?: ");
  421.             double amount = 0;
  422.             try {
  423.                 amount = Double.parseDouble(keyboard.nextLine());
  424.             }
  425.             catch(NumberFormatException e){
  426.                 amount = 0;
  427.             }
  428.             bank.getCustomer(account).getAccount().withdraw(amount); // Example of polymorphism - List aswell
  429.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  430.         }
  431.     }
  432. // Transfer Between Accounts
  433.     private void makeATransfer() {
  434.         displaySubHeader("Transfer funds");
  435.         // First need to select where we want to make the transfer from
  436.         int account = selectAccountTransferFrom(); //  This will call the selection method to select the account
  437.         if (account >= 0) {
  438.             // We are morealess reusing the withdraw method
  439.             System.out.print("Select the amount you want to transfer: ");
  440.             // Set try catch block for validation
  441.             double transferAmount = 0;
  442.            
  443.             try {
  444.                 transferAmount = Double.parseDouble(keyboard.nextLine());
  445.             }
  446.             catch (NumberFormatException e) {
  447.                 transferAmount = 0;
  448.             }
  449.             bank.getCustomer(account).getAccount().withdraw(transferAmount);
  450.            
  451.            
  452.         // Select the transfer destination
  453.         int accountTo = selectAccountTransferTo();
  454.         if (accountTo >= 0) {
  455.                
  456.              bank.getCustomer(accountTo).getAccount().deposit(transferAmount);
  457.            
  458.              System.out.println("You have successfully transfered " + "£" + transferAmount);
  459.  
  460.                
  461.                
  462.             }
  463.            
  464.         }
  465.     }
  466.     // Select Account Transfer From
  467.     private int selectAccountTransferFrom() {
  468.         ArrayList<Customer> customers = bank.getCustomers();
  469.         // The for loop will list all of the customers out // this will likely have to change as they should be shown there accounts once logged in etc
  470.         if (customers.size() <= 0){
  471.             System.out.println("No Customers found!!");
  472.             return -1;
  473.         }
  474.         System.out.println("Select an acccount to transfer from: ");
  475.         for(int i = 0; i < customers.size(); i++) {
  476.             System.out.println((i+1) + ") " + customers.get(i).basicInfo());
  477.         }
  478.         int account = 0;
  479.         System.out.print("Please enter your account selection: ");
  480.         try {
  481.             account = Integer.parseInt(keyboard.nextLine()) - 1; // If they enter 1 then there choice is 0
  482.         }
  483.         catch(NumberFormatException e){
  484.             account = -1;
  485.         }
  486.         if(account < 0 || account > customers.size()) {
  487.             System.out.println("Invalid account - The account doesn't seem to exsist");
  488.             account = -1;
  489.         }
  490.         return account;
  491.     }
  492.    
  493.    
  494.     // Select Account Transfer To
  495.      private int selectAccountTransferTo() {
  496.         ArrayList<Customer> customers = bank.getCustomers();
  497.         // The for loop will list all of the customers out // this will likely have to change as they should be shown there accounts once logged in etc
  498.         if (customers.size() <= 0){
  499.             System.out.println("No Customers found!!");
  500.             return -1;
  501.         }
  502.         System.out.println("Select an acccount to transfer To: ");
  503.         for(int i = 0; i < customers.size(); i++) {
  504.             System.out.println((i+1) + ") " + customers.get(i).basicInfo());
  505.         }
  506.         int account = 0;
  507.         System.out.print("Please enter your account selection: ");
  508.         try {
  509.             account = Integer.parseInt(keyboard.nextLine()) - 1; // If they enter 1 then there choice is 0
  510.         }
  511.         catch(NumberFormatException e){
  512.             account = -1;
  513.         }
  514.         if(account < 0 || account > customers.size()) {
  515.             System.out.println("Invalid account - The account doesn't seem to exsist");
  516.             account = -1;
  517.         }
  518.         return account;
  519.     }
  520.    
  521.  
  522.     private int selectAccount() {              
  523.         ArrayList<Customer> customers = bank.getCustomers();
  524.         // The for loop will list all of the customers out // this will likely have to change as they should be shown their own accounts once logged in etc
  525.         if (customers.size() <= 0){
  526.             System.out.println("No Customers found!!");
  527.             return -1;
  528.         }
  529.         System.out.println("Select an acccount:");
  530.         for(int i = 0; i < customers.size(); i++) {
  531.             System.out.println((i+1) + ") " + customers.get(i).basicInfo());
  532.         }
  533.         int account = 0;
  534.         System.out.print("Please enter your account selection: ");
  535.         try {
  536.             account = Integer.parseInt(keyboard.nextLine()) - 1; // If they enter 1 then there choice is 0
  537.         }
  538.         catch(NumberFormatException e){
  539.             account = -1;
  540.         }
  541.         if(account < 0 || account > customers.size()) {
  542.             System.out.println("Invalid account - The account doesn't seem to exsist");
  543.             account = -1;
  544.         }
  545.         return account;
  546.     }
  547.  
  548.     // Admin Options
  549.     private void adminOptions() {
  550.         printAdminMenu();
  551.         int adminChoice = getAdminInput();
  552.         adminAction(adminChoice);
  553.  
  554.     }
  555.  
  556.     private void printAdminMenu() {
  557.         System.out.println("Admin Options");
  558.         System.out.println("(1) Create an account");
  559.         System.out.println("(2) List Accounts");
  560.         System.out.println("(3) Display Account Balance");
  561.         System.out.println("(4) Display Account Details");
  562.     }
  563.     // Set to int as we are getting an integer
  564.  
  565.     private int getAdminInput() {
  566.         // Reads info from user input - Keyboard and then returns it to the int choice within the run menu method
  567.  
  568.         // Start with a try catch block - nesscary for validtion purposes
  569.         int adminChoice = -1;
  570.         // Do while loop so it at least runs once time
  571.         do {
  572.             System.out.print("Enter your choice: ");
  573.             try {
  574.                 adminChoice = Integer.parseInt(keyboard.nextLine());
  575.  
  576.             }
  577.             catch(NumberFormatException e) {
  578.                 System.out.println("Invalid slection - Please use numbers only");
  579.             }
  580.             if(adminChoice <0 || adminChoice > 6){
  581.                 System.out.println("Please select options between 1 & 6");
  582.             }
  583.  
  584.         }while(adminChoice <0 || adminChoice > 6);
  585.         return adminChoice;
  586.     }
  587.  
  588.     private void adminAction(int adminChoice) {
  589.         switch(adminChoice){
  590.             case 1:
  591.             createAccount();
  592.             break;
  593.             case 2:
  594.             listAccountsAdmin();
  595.             break;
  596.             case 3:
  597.             displayBalanceAdmin();
  598.             break;
  599.             case 4:
  600.             displayDetailsAdmin();
  601.             break;
  602.             // Deafult case just in case - pardon the pun - we wont know what happend
  603.             default:
  604.             System.out.println("Unknown Error has occured");
  605.  
  606.         }
  607.     }
  608.    
  609.  
  610.     // Create a Customer and account
  611.    
  612.     private void createAccount() {
  613.         displaySubHeader("Create an Account");
  614.         String firstName, lastName, accountType = "", ni, username, password;
  615.         double initialDeposit; // Initial Deposit can be used if needed
  616.         boolean valid = false;
  617.         while(!valid){
  618.             System.out.print("Please enter an account type(Basic / Current / Savings): ");
  619.             accountType = keyboard.nextLine();
  620.             if(accountType.equalsIgnoreCase("basic") || accountType.equalsIgnoreCase("current") || accountType.equalsIgnoreCase("savings")) {
  621.                 valid = true;
  622.  
  623.             } else {
  624.  
  625.                 System.out.println("Ooops Invalid account type selected. Please enter basic, current or savings");
  626.  
  627.             }
  628.         }
  629.  
  630.         System.out.print("Please enter customers first name: ");
  631.         firstName = keyboard.nextLine();
  632.         System.out.print("Please enter customers last name: ");
  633.         lastName = keyboard.nextLine();
  634.         System.out.print("Please enter the customers NI number: ");
  635.         ni = keyboard.nextLine();
  636.         System.out.print("Enter a username for the customer: ");
  637.         username = keyboard.nextLine();
  638.         System.out.print("Enter a password for a customer: ");
  639.         password = keyboard.nextLine();
  640.  
  641.         // Time to create an account
  642.         Account account;
  643.         if (accountType.equalsIgnoreCase("current")) {
  644.             account = new Current();
  645.         } else if (accountType.equalsIgnoreCase("basic")) {
  646.  
  647.             account = new Basic();
  648.         } else {
  649.  
  650.             account = new Savings();
  651.  
  652.         }
  653.         // Create Customer
  654.         Customer customer = new Customer(firstName, lastName, ni, username, password, account);
  655.         bank.addCustomer(customer);
  656.     }
  657.  
  658.     private void listAccountsAdmin() {
  659.         displaySubHeader("List Accounts");
  660.          ArrayList<Customer> customers = bank.getCustomers();
  661.         if (customers.size() <= 0){
  662.             System.out.println("No Customers found!!");
  663.            
  664.         }
  665.         System.out.println("Select an acccount:");
  666.         for(int i = 0; i < customers.size(); i++) {
  667.             System.out.println((i+1) + ") " + customers.get(i).basicInfo());
  668.         }      
  669.     }
  670.  
  671.     private void displayBalanceAdmin() {
  672.         displaySubHeader("Display Balance");
  673.         int account = selectAccount();
  674.         if (account >= 0 ) {
  675.             // Get balance by calling getBalance
  676.             System.out.println("Your balance is: £" + bank.getCustomer(account).getAccount().getBalance()); // Example of polymorphism aswell as list account details
  677.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  678.         }
  679.     }
  680.  
  681.     private void displayDetailsAdmin() {
  682.         displaySubHeader("Account Details");
  683.         int account = selectAccount();
  684.         if (account >= 0 ) {
  685.             // Get balance by calling getBalance
  686.             System.out.println(bank.getCustomer(account).getAccount()); // Example of polymorphism aswell as list account details
  687.             // We have our bank then we get the customer then we get the account of which they would want to deposit to then we deposit the amount
  688.         }
  689.     }
  690.    
  691.     // Set the custom sub header print
  692.    
  693.     private void displaySubHeader(String message){ // Message passing
  694.         System.out.println(); // Creates a space between other menus and options etc between each of the headers
  695.        
  696.         int width = message.length() + 6;
  697.         StringBuilder sBuilder = new StringBuilder(); // StringBuilder lets you build up a string rarther than making a new one etc
  698.         // More effiant than the other option which would be concatination
  699.         sBuilder.append(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "+" + ANSI_RESET);
  700.         for (int i = 0; i < width; ++i){
  701.             sBuilder.append(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "=" + ANSI_RESET);
  702.         }
  703.         sBuilder.append(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "+" + ANSI_RESET);
  704.         System.out.println(sBuilder.toString());
  705.         System.out.println(ANSI_WHITE_BACKGROUND + ANSI_BLUE + "    " + message + "    " + ANSI_RESET);
  706.         System.out.println(sBuilder.toString());
  707.     }
  708. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement