{"id":127,"date":"2025-11-23T20:24:25","date_gmt":"2025-11-23T20:24:25","guid":{"rendered":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/?p=127"},"modified":"2025-11-23T20:25:32","modified_gmt":"2025-11-23T20:25:32","slug":"atm-test-w-array-lists","status":"publish","type":"post","link":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/2025\/11\/23\/atm-test-w-array-lists\/","title":{"rendered":"ATM Test w\/Array Lists"},"content":{"rendered":"\n<p>\/*<\/p>\n\n\n\n<ul>\n<li>Click nbfs:\/\/nbhost\/SystemFileSystem\/Templates\/Licenses\/license-default.txt to change this license<\/li>\n\n\n\n<li>Click nbfs:\/\/nbhost\/SystemFileSystem\/Templates\/Classes\/Main.java to edit this template<\/li>\n\n\n\n<li>Name: Carter Hendrick<\/li>\n\n\n\n<li>Course Name: IT_205_Object Oriented Programming w\/ Java<\/li>\n\n\n\n<li>Date: 10\/14\/2025<\/li>\n\n\n\n<li>Pledge: This program is entirely written by me (Carter Hendrick) with the exception of the starting point provided by the professor<br><em>\/ \/<\/em><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/ package atmtest; import java.util.*;\n\npublic class ATMTest {\npublic static void main(String&#091;] args) {\n\n    \/\/declare some variables\n    Scanner input = new Scanner(System.in);\n\n    \/\/declare an array list of customers\n    ArrayList&lt;ATM&gt; customers = new ArrayList&lt;&gt;();\n\n    String firstName;\n    double balance;\n    int pin;\n\n    for(int count = 0; count&lt;3; count++){\n        System.out.println(\"CUSTOMER #\"+count);\n\n        System.out.print(\"Enter one word name of customer: \");\n        firstName = input.next();\n\n        System.out.print(\"Enter your customers pin: \");\n        pin = input.nextInt();\n\n        System.out.print(\"Enter your customers balance: \");\n        balance = input.nextDouble(); \n        System.out.println(\"END OF CUSTOMER #\"+count+\"\\n\");\n\n    \/\/create an instance of ATM\n    ATM customer1 = new ATM(firstName, pin, balance);\n\n    customers.add(customer1);  \/\/added an instance of ATM to the arraylist\n\n    }\/\/end of for loop creating arraylist\n\n    \/\/output list of customers\n\n    for(int count = 0; count&lt;customers.size(); count++){\n\n    System.out.printf(\"%10s%5d%10.2f%n\",\n            customers.get(count).getName(),\n            customers.get(count).getPin(),\n            customers.get(count).getBalance());\n    }\/\/end of customer output for loop\n\n\n\n    \/\/SAY THAT THE INDEX OF THE ELEMENT WHOSE PIN MATCHED WAS \n   \/\/ int index = 2;\n    \/\/how to call the deposit method\n    \/\/customers.get(index).deposit(103);\n   \/\/  System.out.println(\"Your new balance is \"+\n           \/\/  customers.get(index).getBalance());\n\n\n\n\n\n\n    \/\/start infinite while loop\n     while(true){\n      \/\/prompt and read somepin\n      System.out.println(\"Welcome to my Bank\");\n      System.out.print(\"Enter your pin: \");\n      \/\/read the pin\n      int somePin = input.nextInt();\n      System.out.println(\"You entered \"+somePin);\n   \/* USE A FOR LOOP AND DETERMINE THE INDEX OF THE CUSTOMER WHOSE PIN MATCHES\n    THE INPUT PIN\n    INSIDE THIS LOOP HAVE A BOOL VARIABLE THAT TURNS TRUE IF THERE IS A MATCH\n    IF NO MATCH GO TO TOP OF LOOP -CONTINUE\n   *\/\n   int Index = 0;\n   boolean pinMatch = false;\n   for (int i = 0; i &lt; customers.size(); i++)\n   {\n       if (customers.get(i).equals(somePin))\n       {\n           Index = i;\n           pinMatch = true;\n           break;\n       }else{\n           continue;\n       }\n   }\n    if (pinMatch = true) {\n        System.out.println(\"PIN matched! Customer found at index: \" + Index);\n        System.out.println(\"Customer Name: \" + customers.get(Index).getName());\n        System.out.println(\"Customer Balance: \" + customers.get(Index).getBalance());\n    } else {\n        System.out.println(\"No customer found with the given PIN.\");\n    }\n\n    \/\/output menu -deposit, withdraw,  or exit\n    if(pinMatch = true){\n     System.out.printf(\" %s%s%n\", \"Welcome \",\n             customers.get(Index).getName());\n     System.out.printf(\" %s%s%n\",\" balance: $\",\n             customers.get(Index).getBalance());\n     balance = customers.get(Index).getBalance();\n     boolean exit = false;\n     while (!exit) {\n         System.out.println(\"1. Withdraw\");\n         System.out.println(\"2. Deposit\");\n         System.out.println(\"3. Exit\");\n         System.out.println(\"Please select an option: \");\n         int option = input.nextInt();\n         switch (option) {\n             case 1 -&gt; { \n                 \/\/withdraw\n                 System.out.print(\"Enter amount to withdraw: \");\n                 double withdrawAmount = input.nextDouble();\n                 customers.get(Index).withdraw(withdrawAmount);\n                 System.out.printf(\" %s%s%n\",\" balance: $\",\n                        customers.get(Index).getBalance());\n             }\n             case 2 -&gt; { \n                 \/\/Deposit\n                 System.out.print(\"Enter amount to deposit: \");\n                 double depositAmount = input.nextDouble();\n                 customers.get(Index).deposit(depositAmount);\n                 System.out.printf(\" %s%s%n\",\" balance: $\",\n                         customers.get(Index).getBalance());\n             }\n             case 3 -&gt; {\n                 exit = true;\n                break;\n             }\n             default -&gt; {\n                 System.out.print(\"invalid choice, please try again\");\n             }\n         }\n     }\n    }\n     }\n}\npublic static void main(String&#091;] args) {\n\n    \/\/declare some variables\n    Scanner input = new Scanner(System.in);\n\n    \/\/declare an array list of customers\n    ArrayList&lt;ATM&gt; customers = new ArrayList&lt;&gt;();\n\n    String firstName;\n    double balance;\n    int pin;\n\n    for(int count = 0; count&lt;3; count++){\n        System.out.println(\"CUSTOMER #\"+count);\n\n        System.out.print(\"Enter one word name of customer: \");\n        firstName = input.next();\n\n        System.out.print(\"Enter your customers pin: \");\n        pin = input.nextInt();\n\n        System.out.print(\"Enter your customers balance: \");\n        balance = input.nextDouble(); \n        System.out.println(\"END OF CUSTOMER #\"+count+\"\\n\");\n\n    \/\/create an instance of ATM\n    ATM customer1 = new ATM(firstName, pin, balance);\n\n    customers.add(customer1);  \/\/added an instance of ATM to the arraylist\n\n    }\/\/end of for loop creating arraylist\n\n    \/\/output list of customers\n\n    for(int count = 0; count&lt;customers.size(); count++){\n\n    System.out.printf(\"%10s%5d%10.2f%n\",\n            customers.get(count).getName(),\n            customers.get(count).getPin(),\n            customers.get(count).getBalance());\n    }\/\/end of customer output for loop\n\n\n\n    \/\/SAY THAT THE INDEX OF THE ELEMENT WHOSE PIN MATCHED WAS \n   \/\/ int index = 2;\n    \/\/how to call the deposit method\n    \/\/customers.get(index).deposit(103);\n   \/\/  System.out.println(\"Your new balance is \"+\n           \/\/  customers.get(index).getBalance());\n\n\n\n\n\n\n    \/\/start infinite while loop\n     while(true){\n      \/\/prompt and read somepin\n      System.out.println(\"Welcome to my Bank\");\n      System.out.print(\"Enter your pin: \");\n      \/\/read the pin\n      int somePin = input.nextInt();\n      System.out.println(\"You entered \"+somePin);\n   \/* USE A FOR LOOP AND DETERMINE THE INDEX OF THE CUSTOMER WHOSE PIN MATCHES\n    THE INPUT PIN\n    INSIDE THIS LOOP HAVE A BOOL VARIABLE THAT TURNS TRUE IF THERE IS A MATCH\n    IF NO MATCH GO TO TOP OF LOOP -CONTINUE\n   *\/\n   int Index = 0;\n   boolean pinMatch = false;\n   for (int i = 0; i &lt; customers.size(); i++)\n   {\n       if (customers.get(i).equals(somePin))\n       {\n           Index = i;\n           pinMatch = true;\n           break;\n       }else{\n           continue;\n       }\n   }\n    if (pinMatch = true) {\n        System.out.println(\"PIN matched! Customer found at index: \" + Index);\n        System.out.println(\"Customer Name: \" + customers.get(Index).getName());\n        System.out.println(\"Customer Balance: \" + customers.get(Index).getBalance());\n    } else {\n        System.out.println(\"No customer found with the given PIN.\");\n    }\n\n    \/\/output menu -deposit, withdraw,  or exit\n    if(pinMatch = true){\n     System.out.printf(\" %s%s%n\", \"Welcome \",\n             customers.get(Index).getName());\n     System.out.printf(\" %s%s%n\",\" balance: $\",\n             customers.get(Index).getBalance());\n     balance = customers.get(Index).getBalance();\n     boolean exit = false;\n     while (!exit) {\n         System.out.println(\"1. Withdraw\");\n         System.out.println(\"2. Deposit\");\n         System.out.println(\"3. Exit\");\n         System.out.println(\"Please select an option: \");\n         int option = input.nextInt();\n         switch (option) {\n             case 1 -&gt; { \n                 \/\/withdraw\n                 System.out.print(\"Enter amount to withdraw: \");\n                 double withdrawAmount = input.nextDouble();\n                 customers.get(Index).withdraw(withdrawAmount);\n                 System.out.printf(\" %s%s%n\",\" balance: $\",\n                        customers.get(Index).getBalance());\n             }\n             case 2 -&gt; { \n                 \/\/Deposit\n                 System.out.print(\"Enter amount to deposit: \");\n                 double depositAmount = input.nextDouble();\n                 customers.get(Index).deposit(depositAmount);\n                 System.out.printf(\" %s%s%n\",\" balance: $\",\n                         customers.get(Index).getBalance());\n             }\n             case 3 -&gt; {\n                 exit = true;\n                break;\n             }\n             default -&gt; {\n                 System.out.print(\"invalid choice, please try again\");\n             }\n         }\n     }\n    }\n     }\n}\n}<\/code><\/pre>\n\n\n\n<p>ATM methods<\/p>\n\n\n\n<p>\/*<\/p>\n\n\n\n<ul>\n<li>Click nbfs:\/\/nbhost\/SystemFileSystem\/Templates\/Licenses\/license-default.txt to change this license<\/li>\n\n\n\n<li>Click nbfs:\/\/nbhost\/SystemFileSystem\/Templates\/Classes\/Main.java to edit this template<\/li>\n\n\n\n<li>Name: Carter Hendrick<\/li>\n\n\n\n<li>Course Name: IT_205_Object Oriented Programming w\/ Java<\/li>\n\n\n\n<li>Date: 10\/14\/2025<\/li>\n\n\n\n<li>Pledge: This program is entirely written by me (Carter Hendrick) without help from anyone<br>*\/<\/li>\n<\/ul>\n\n\n\n<p>\/**<br>*<\/p>\n\n\n\n<ul>\n<li>@author hendr<br><em>\/ \/<\/em><br>ATM class with instance members and methods<br>*\/<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>package atmtest;\npublic class ATM {\n\/\/declare the instance variables\nString firstName;\n\/\/others such as pin and balance\nint pin;\ndouble balance;\n\n\/\/construtor with parameters\npublic ATM(String someFirstName, int somePin, double someBalance){\n    this.firstName = someFirstName;\n    this.pin = somePin;\n    this.balance = someBalance;\n}\/\/end of constructor\n\n\/\/get and set methods\n\n\/\/get method for the name\npublic String getName(){\n    return this.firstName;\n}\/\/end of getName\n\npublic double getBalance(){\n    return this.balance;\n}\n\npublic int getPin(){\n    return this.pin;\n}\n\n\/\/create a public method to deposit\n\npublic void deposit(double depAmt){\n    if(depAmt&gt;=0){\n        this.balance+=depAmt;\n    }\/\/end of if\n\n    }\n\n\/\/create a public method to deposit\n\npublic void withdraw(double depAmt){\n    if(depAmt&gt;=0){\n        this.balance-=depAmt;\n    }\/\/end of if\n}\n}\/\/end of ATM<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* ATM methods \/* \/***<\/p>\n","protected":false},"author":25850,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","wds_primary_category":9},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/posts\/127"}],"collection":[{"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/users\/25850"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":2,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/posts\/127\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/carterhendrick-eportfolio\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}