CSCI 185 ATM Software Design Vadim Kan Student ID: 1291891 1 Contents Introduction .................................................................................................................................................. 2 SLC (Software Life Cycle) Description and Spiral Method ............................................................................ 2 CRC Cards ...................................................................................................................................................... 4 UML Diagram ................................................................................................................................................ 5 Method Documentation ............................................................................................................................... 6 Implementation of Classes............................................................................................................................ 8 ATM ........................................................................................................................................................... 9 checkingAccount ..................................................................................................................................... 11 savingsAccount ....................................................................................................................................... 12 Tester ...................................................................................................................................................... 13 Conclusion: .................................................................................................................................................. 18 Troubleshooting .......................................................................................................................................... 19 Introduction We are asked to design an ATM (Automated Teller Machine) for customers for a bank. We will implement a unique customer number and PIN (personal identification number). These are both required to be entered for access to the ATM. There will be options to use the checking and savings accounts and a termination as well. Each of the accounts will have two options of deposit and withdrawal as well displaying the balance when they are selected. All accounts used in the simulation will have a balance of 0. SLC (Software Life Cycle) Description and Spiral Method The software life cycle is the process of developing a program from the initial idea and development to the retirement of the program. A software is usually made as a solution to address a problem. The software life cycle consists of five stages that are used in the spiral method to break down the development process. The spiral method works in prototypes that demonstrate the evolution of the program throughout the different stages and how it has been made to achieve the goal it is intended for. Analysis – in this phase we determine the goal of our project and try to figure out why rather than how, to outline how we are going to program the software. We will create a document that will describe what features and things the program will do once it is completed, a user manual to help a user to operate the program properly so it can accomplish the goal of the software. 3 The preconditions of the program are also indicated in this phase such as how much data the program will take at a time, storage requirements, and the maximum processing and memory usage. Design – during this stage we will develop a plan to implement the software to solve the problem we have designated in the analysis stage. We will create structures to solve the problem and determine what classes and methods are required to complete the task using object-oriented design. Classes, methods, and UML diagram will be described and shown to display the relationship. Implementation – we will write, compile, and implement code and items discussed in the design phase and the output will be completed. Testing – we will run data to debug the program to fix any errors whether compilation or runtime. Deployment – the program will be deployed and will perform the intended goal and purpose. _____________________________________________________________________________________ Analysis – The goal of the project is to create a text-based simulation of an ATM that has a checking and savings account for a respective account number and pin. The program will take user inputs to display balance, access both checking and savings to deposit and withdraw, updating the balance and quitting the program. It can take user entries in the main menu to access the checking or savings account and quit the program. After accessing either of the accounts, there will an input to deposit, withdraw, or cancel the function, prompting you back to the main menu. Design: We will use a main ATM class that will be interact with two other classes: checkingAccount and savingsAccount. These classes will have functions respective to their name and will work with ATM so that they can function in unison. The classes and methods will be described further in the following sections and within the CRC cards. Other parts of the software life cycle will be explicated on further in the write-up. CRC Cards We will use the classes, responsibilities, and collaborators (CRC) method to understand the relationship between the classes and their function. ATM - - communicate with the checking and savings account classes it will run and execute the program access the data in the other classes to grant entry to both classes, and afterwards print out the balance etc. from the respective classes it will exit and initiate program based on the user entry it will check for errors in the user entry as well as interactions in the console will check the user data (account number & pins) interact with both account classes to change their data with user entries display data into the console - checkingAccount, savingsAccount - checkingAccount contains checking balance of the - ATM respective account number can create the checking account with constructor and return values such as balance and has methods: deposit and withdrawal interacts with ATM class to allow access - savingsAccount - ATM - - - contains savings balance of the respective account number can create the savings account with constructor and return values such as balance and has methods: deposit and withdrawal interacts with ATM class to allow access 5 UML Diagram The ATM class will be the super class responsible for allowing the checking and savings account to inherit ATM checkingAccount savingsAccount Method Documentation import java.io.FileReader; //used to access the text file containing the data for the ATM import java.io.IOException; //catches exceptions in regards to the input and output of files import java.util.Scanner; //used in conjunction with file reader to read the values inside the text file import java.util.ArrayList; //used in passing the values from the text file to the object, allows for scaling /* will deal with file access and making sure the correct account number and pin are entered */ public class ATM { private static int account; //contains a static account number because we are using it inside main private static int pin; //contains a static pin because we are using inside the main private String file; //contains the file path in String form /* will initialize file to the file path passed to the constructor */ public ATM(String n) {...} /* opens the file, reading it and converting the strings to integers */ public void open () {...} /* matches user inputs to the account number and pin located inside the file */ public static Boolean match (int a, int p) {...} } //END OF CLASS ------------------------------------------------------------------------------------------------------------------------------------------ /* after receiving a true boolean it will run, and the methods will be called from this class*/ public class checkingAccount { private double balance; /* will create a checkingAccount object with balance of 0 */ public checkingAccount () {...} /* deposit money to the account */ 7 public void deposit (double n) {...} /* withdraw money from the account and return an error code if the withdrawal is negative */ public void withdrawal (double n) {...} /* return the balance of the object as a double */ public double getBalance () {...} } //END OF CLASS ------------------------------------------------------------------------------------------------------------------------------------------ /* after receiving a true boolean it will run, and the methods will be called from this class*/ public class savingsAccount { private double balance; /* will create a savingsAccount object with balance of 0 */ public checkingAccount () {...} /* deposit money to the account */ public void deposit () {...} /* withdraw money from the account and return a error code if the withdrawal is negative */ public void withdrawal (double n) {...} /* return the balance of the object as a double */ public double getBalance (double n) {...} } //END OF CLASS -------------------------------------------------------------------------------------------------------------------------------------------------------- import java.io.FileNotFoundException; // responsible for checking if the file path is correct import java.io.IOException; //responsible for catching a FileNotFoundException between ATM and Tester import java.util.Scanner; //Initiated here again to take user inputs from the terminal /* Class responsible for testing all the functionality of the ATM, checking and savings account classes */ public class Tester { public static void main (String [] args) throws IOException { //throws exception if file not found Scanner input = new Scanner(System.in); int error = 0; //stores the number of invalid combinations of account number and pin final int failState = 2; //maximum number of times you can attempt after one invalid try String entry = “”; //temporary string to take user entry during the simulation String choice = “”; //temporary string to make sure user entry matches the testing values Boolean testing = false; //variable to store the boolean return of the match method in ATM try {...} //tries to open the file with the file path indicated catch (FileNotFoundException e) {...} //throws exception if the file was not found while(!testing) {...} //checks for correct combination and allows for multiple attempts checkingAccount accOne = new checkingAccount(); //creates checking account savingsAccount accTwo = new savingsAccount(); //creates savings account while(!choice.equals(“C”) ) {...} //runs an infinite text simulation until user terminates } } Implementation of Classes 9 ATM: This class will be the main class responsible for the user interaction and will interact with the checking and savings account classes. It will also be responsible for the security of the program, checking the user’s entries for the correct account number and pin combination. It will have an error state and will work with the account classes by passing a boolean to check whether you should proceed with the code or not. The Scanner object will be declared and initialized to the same name as the ones written in this section in the Tester class. checkingAccount: This class will create a checkingAccount object that has a balance of 0 and will have deposit and withdraw methods. It will only run in the case of receiving a true boolean state from the ATM class method match. savingsAccount: This class will create a savingsAccount object that has a balance of 0 and will have deposit and withdraw methods. It will only run in the case of receiving a true boolean state from the ATM class method match. ATM import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import java.util.ArrayList; public class ATM { private static int account; private static int pin; private String file; public ATM(String n) { file = n; } public void open () throws IOException { FileReader reader = new FileReader(file); Scanner input = new Scanner(reader); ArrayList <String> temp = new ArrayList <String> (); for (int i = 0; i < 2; i++) { temp.add(input.nextLine() ); } account = Integer.parseInt(temp.get(0) ); pin = Integer.parseInt(temp.get(1) ); } public static Boolean match (int a, int p) { if (a == account) { if (p == pin) return true; else return false; } else return false; 11 } } //END OF CLASS checkingAccount public class checkingAccount { private double balance; public checkingAccount() { balance = 0; } public void deposit(double n) { balance += n; } public void withdrawal() { if (balance – n < 0) System.out.println(“Withdrawal not possible.”); else balance -= n; } public double getBalance() { return balance; } } //END OF CLASS savingsAccount public class savingsAccount { private double balance; public savingsAccount() { 13 balance = 0; } public void deposit(double n) { balance += n; } public void withdrawal() { if (balance – n < 0) System.out.println(“Withdrawal not possible.”); else balance -= n; } public double getBalance() { return balance; } } //END OF CLASS Tester import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; public class Tester { public static void main (String [] args) throws IOException { Scanner input = new Scanner(System.in); int error = 0; final int failState = 2; Boolean testing = false; try { ATM sample = new ATM(“D:/nyit/Spring 2022 Semester/CSCI 185/Homework/atmData.txt”); sample.open(); } catch (FileNotFoundException e) { System.out.println(“File not found, please run again.”); System.exit(0); } while (!testing) { System.out.print(“Enter account number.”); int temp = input.nextInt(); System.out.print(“Enter pin.”); int temp2 = input.nextInt(); testing = ATM.match(temp, temp2); if (testing == false) { 15 error++; System.out.println(“You have entered the wrong combination. You have “ + (failState – error) + “ attempts left.”); } if (error == failState) { System.out.println(“Number of attempts exceeded.”); System.exit(0); } } checkingAccount accOne = new checkingAccount(); savingsAccount accTwo = new savingsAccount(); while(!choice.equalsIgnoreCase(“C”) ) { System.out.println(“A = Checking \nB = savings \nC = savings”); entry = input.next(); choice = entry.toUpperCase(); if (choice.equalsIgnoreCase(“A”) ) { String choice2 = “”; while(!choice2.equalsIgnoreCase(“C”) ) { System.out.println(“Checking Account: ” + accOne.getBalance() ); System.out.println(“A = Deposit \nB = Withdrawal \nC = Cancel Operation”); entry = input.next(); choice2 = entry.toUpperCase(); if (choice2.equalsIgnoreCase(“A”) ) { System.out.print(“Amount:”); double tempA = input.nextDouble(); accOne.deposit(tempA); } else if (choice2.equalsIgnoreCase(“B”) ) { System.out.print(“Amount:”); double tempA = input.nextDouble(); if (tempA < 0) { System.out.println(“Try again.”); break; } accOne.withdrawal(tempA); } } } if (choice.equalsIgnoreCase(“B”) ) { String choice2 = “”; while(!choice2.equalsIgnoreCase(“C”) ) { 17 System.out.println(“Savings Account: “ + accOne.getBalance() ); System.out.println(“A = Deposit \nB = Withdrawal \nC = Cancel Operation”); entry = input.next(); choice2 = entry.toUpperCase(); if (choice2.equalsIgnoreCase(“A”) ) { System.out.print(“Amount:”); double tempA = input.nextDouble(); accTwo.deposit(tempA); } else if (choice2.equalsIgnoreCase(“B”) ) { System.out.print(“Amount:”); double tempA = input.nextDouble(); if (tempA < 0) { System.out.println(“Try again.”); break; } accOne.withdrawal(tempA); } } } } } } Conclusion: Presentations of the different cases that occur during the code and exceptions that are handled: 19 Case 1: Exception handled in main class, with wrong file path. Case 2: Number of attempts to enter correct combination exceeded and the program closed itself. Case 3: Correct combination entered, and the text simulation starts running, some commands are made. Case 4: Correct combination entered again, text simulation ran and returned code back to main menu of that account because withdrawal was not possible. Troubleshooting Problems with Design: - Initial design of the program was going to use an extra customer class to control the security but scrapped for simplicity. Inheritance usage scrapped for aggregation to simplify code and avoid problems with super calls. ATM Class: - Most problems stemmed from this class due to the reading of the file and using RandomAccessFile compared to FileReader. FileReader chosen for reading the file because it can read the text file and parse it to an int. All methods and both account and pin must be static because Tester contains the public static void main. A lot of methods relating to RandomAccessFile were cut, making the code shorter because it was simpler to use FileReader and return information as well as matching the user inputted values. Pin was changed from double to int because there is no point of having it be a different value, double was initially used for differentiating between values in RandomAccessFile. No issues found in either checking or savings account classes because the functions were easy to program and had almost no change. Only improvement would be creating a specific exception for negative values or invalid withdrawals but that is redundant. Tester Class: - Since this is the main and tests everything as well as running the text simulation it had the most complications. Organization problems with the temporary variable declaration so they have class scope instead of method scope in use during the simulation and testing. Separate boolean had to be made for testing the return value from the match method and allowed for improved readability. Try and catch block had some issues due to having throws IOException in the class and main header. File path needed to be specified rather than just the file name. Learned the use of the exit method from the System package to exit the program when exceptions were caught. While loop for testing the failState had some issues in printing out the correct number of left attempts left of the user. While loops had to work in unison to make sure the simulation would run endlessly unless the user canceled or terminated the program. Quality of life changes to make sure the user could understand which account was being accessed at the current moment.