diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..51933c0 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7aa1668 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1b71739 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ded0884 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1474072078341 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..572780f --- /dev/null +++ b/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + crawley.james + project-2-atm + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + junit + junit + RELEASE + test + + + + \ No newline at end of file diff --git a/project-2-atm.iml b/project-2-atm.iml new file mode 100644 index 0000000..6ad1e66 --- /dev/null +++ b/project-2-atm.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/crawley/james/project2atm/ATM.java b/src/main/java/crawley/james/project2atm/ATM.java new file mode 100644 index 0000000..9ee37a6 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/ATM.java @@ -0,0 +1,293 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class ATM { + + private int accountNumCounter = 1; + private int customerIDCounter = 1; + private UserInputHandler userInputHandler = new UserInputHandler(); + private Display display = new Display(); + private int currentUser; + private boolean running = true; + private boolean loggedIn = false; + private AccountManager accountManager = new AccountManager(); + private TransactionManager transactionManager = new TransactionManager(); + private CustomerManager customerManager = new CustomerManager(); + + public void startATM () { + + while (running) { + + display.printWelcomeScreen(); + + switch (userInputHandler.getUserInt()) { + + case 1: + + display.printNewCustomerMenu(); + String name = userInputHandler.getUserString() + userInputHandler.getUserString(); + createCustomer(name , getValidUserInt()); + break; + + case 2: + display.printLogin(); + loginUserIfValidInfo(); + break; + case 3: + + running = false; + break; + default: + display.printOptionErrorMessage(); + + } + } + + } + + public void accessServices () { + + while (loggedIn) { + display.printReturningCustomerMenu(); + switch (getValidUserInt()) { + case 1: + accountTypeOptions(); + break; + case 2: + display.closeAccountPrompt(); + closeAccount(getValidUserInt(), currentUser); + break; + case 3: + display.transactionPrompt("deposit"); + deposit(getValidUserInt(), getValidUserDouble()); + break; + case 4: + display.transactionPrompt("withdrawal"); + withdrawals(getValidUserInt(), getValidUserDouble()); + break; + case 5: + display.transactionPrompt(); + transfer(getValidUserInt(), getValidUserInt(), getValidUserDouble()); + break; + case 6: + transactions(); + break; + case 7: + loggedIn = false; + currentUser = 0; + break; + default: + display.printOptionErrorMessage(); + } + } + + } + + public void accountTypeOptions () { + + Account.AccountType accountType = null; + + while (accountType == null) { + display.printAccountTypeOptions(); + switch (getValidUserInt()) { + + case 1: + accountType = Account.AccountType.CHECKING; + break; + case 2: + accountType = Account.AccountType.SAVINGS; + break; + case 3: + accountType = Account.AccountType.INVESTMENT; + break; + default: + display.printOptionErrorMessage(); + } + } + + display.createAccountPrompt(); + createAccount(accountType, currentUser, accountNumCounter, getValidUserDouble()); + display.printSuccessfulCreation("Account", accountNumCounter); + accountNumCounter++; + } + + public boolean verifyLoginInfo (int customerID, int pin) { + + if (customerManager.getCustomer(customerID).getPin() == pin) { + + loggedIn = true; + return true; + + } else { + + return false; + } + + } + + public void createCustomer (String name, int pin) { + + customerManager.addCustomer(name, pin, customerIDCounter); + display.printSuccessfulCreation("Customer", customerIDCounter); + customerIDCounter++; + + } + + public void createAccount (Account.AccountType accountType, int customerID, int accountNumber ,double amount) { + + accountManager.addAccount(accountType, amount, customerID, accountNumber); + display.transactionSuccessMessage(getUserBalance(accountNumber)); + + } + + public void closeAccount (int accountNumber, int customerID) { + + int closedMessageCase = 0; + + if (!isRealAccount(accountNumber)) { + + closedMessageCase = 1; + + } else if (isAccountBalanceZero(accountNumber, customerID)) { + + accountManager.deleteAccount(accountNumber, customerID); + closedMessageCase = 2; + } + + display.closeAccountMessage(closedMessageCase); + } + + public boolean isAccountBalanceZero (int accountNumber, int customerID) { + + if (accountManager.getAccount(accountNumber, customerID).getBalance() == 0) { + return true; + } else { + return false; + } + } + + public void withdrawals (int accountNumber, double amount) { + + if (isRealAccount(accountNumber)) { + setUserBalance(getUserBalance(accountNumber) - amount, accountNumber); + transactionManager.addTransaction(Transaction.TransactionType.WITHDRAWAL, currentUser, accountNumber, amount); + display.transactionSuccessMessage(getUserBalance(accountNumber)); + } else { + + display.transactionErrorMessage(); + } + + } + + public void deposit (int accountNumber, double amount) { + + if (isRealAccount(accountNumber)) { + setUserBalance(getUserBalance(accountNumber) + amount, accountNumber); + transactionManager.addTransaction(Transaction.TransactionType.DEPOSIT, currentUser, accountNumber, amount); + display.transactionSuccessMessage(getUserBalance(accountNumber)); + } else { + + display.transactionErrorMessage(); + } + + } + + public void transfer (int fromAccountNumber, int toAccountNumber, double amount) { + + if (isRealAccount(fromAccountNumber) && isRealAccount(toAccountNumber)) { + withdrawals(fromAccountNumber, amount); + deposit(toAccountNumber, amount); + transactionManager.addTransaction(currentUser, fromAccountNumber, toAccountNumber, amount); + display.transactionSuccessMessage(getUserBalance(fromAccountNumber)); + } else { + display.transactionErrorMessage(); + } + } + + public void transactions () { + + transactionManager.printTransactions(currentUser); + + } + + public AccountManager getAccountManager () { + + return accountManager; + } + + public CustomerManager getCustomerManager () { + + return customerManager; + + } + + public TransactionManager getTransactionManager () { + + return transactionManager; + + } + + public void setCurrentUser (int currentUser) { + + this.currentUser = currentUser; + } + + private double getUserBalance (int accountNumber) { + + return accountManager.getAccount(accountNumber, currentUser).getBalance(); + + } + + private void setUserBalance (double amount, int accountNumber) { + accountManager.getAccount(accountNumber, currentUser).setBalance(amount); + } + + private int getValidUserInt() { + int val; + + do { + val = userInputHandler.getUserInt(); + } while (val == 0); + + return val; + } + + private double getValidUserDouble() { + double val; + + do { + val = userInputHandler.getUserDouble(); + } while (val == 0); + + return val; + } + + private void loginUserIfValidInfo () { + + int customerID = getValidUserInt(); + + if (verifyLoginInfo(customerID, getValidUserInt())) { + currentUser = customerID; + accessServices(); + } else { + display.invalidLoginMessage(); + } + + } + + private boolean isRealAccount (int accountNumber) { + + if (accountManager.getAccount(accountNumber, currentUser) != null) { + + return true; + + } else { + + return false; + } + + } + +} diff --git a/src/main/java/crawley/james/project2atm/Account.java b/src/main/java/crawley/james/project2atm/Account.java new file mode 100644 index 0000000..4162726 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/Account.java @@ -0,0 +1,79 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class Account { + + public enum AccountType {SAVINGS, CHECKING, INVESTMENT;} + + private AccountType accountType; + private double balance; + private int accountNumber; + private int customerID; + private double interestRate; + + public Account(AccountType accountType, double balance, int customerID, int accountNumber) { + + this.accountType = accountType; + this.balance = balance; + this.customerID = customerID; + this.accountNumber = accountNumber; + setInterestRate(accountType); + + + } + + + public AccountType getAccountType() { + + return accountType; + + } + + public int getAccountNumber() { + + return accountNumber; + + } + + public void setInterestRate(AccountType accountType) { + + switch (accountType) { + + case SAVINGS: + interestRate = 0.05; + break; + case CHECKING: + interestRate = 0.02; + break; + case INVESTMENT: + interestRate = 0.07; + break; + default: + System.out.println("Not a valid account type"); + } + } + + public double getInterestRate() { + + return interestRate; + + } + + public void setBalance(double balance) { + + this.balance = balance; + } + + public double getBalance() { + + return balance; + } + + public int getCustomerID() { + + return customerID; + } + +} diff --git a/src/main/java/crawley/james/project2atm/AccountManager.java b/src/main/java/crawley/james/project2atm/AccountManager.java new file mode 100644 index 0000000..803c189 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/AccountManager.java @@ -0,0 +1,42 @@ +package crawley.james.project2atm; + +import java.util.ArrayList; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class AccountManager { + + private ArrayList accounts = new ArrayList<>(); + + public void addAccount (Account.AccountType accountType, double amount, int customerID, int accountNumber) { + + accounts.add(new Account(accountType, amount, customerID, accountNumber)); + + } + + public void deleteAccount (int accountID, int customerID) { + + for (Account matchingAccount: accounts) { + if (matchingAccount.getAccountNumber() == accountID && matchingAccount.getCustomerID() == customerID) { + accounts.remove(matchingAccount); + break; + } + + } + } + + public Account getAccount (int accountID, int customerID) { + + for (Account matchingAccount: accounts) { + if (matchingAccount.getAccountNumber() == accountID && matchingAccount.getCustomerID() == customerID) { + return matchingAccount; + } + + } + + return null; + + } + +} diff --git a/src/main/java/crawley/james/project2atm/Customer.java b/src/main/java/crawley/james/project2atm/Customer.java new file mode 100644 index 0000000..9eb32cf --- /dev/null +++ b/src/main/java/crawley/james/project2atm/Customer.java @@ -0,0 +1,50 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class Customer { + + private int customerID; + + private String name; + private int pin; + + Customer (String name, int pin, int customerID) { + + this.name = name; + this.pin = pin; + this.customerID = customerID; + + } + + public void setName (String name) { + + this.name = name; + + } + + public String getName () { + + return name; + + } + + public void setPin (int pin) { + + this.pin = pin; + + } + + public int getPin () { + + return pin; + + } + + public int getCustomerID () { + + return customerID; + } + +} diff --git a/src/main/java/crawley/james/project2atm/CustomerManager.java b/src/main/java/crawley/james/project2atm/CustomerManager.java new file mode 100644 index 0000000..c0a5a07 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/CustomerManager.java @@ -0,0 +1,28 @@ +package crawley.james.project2atm; + +import java.util.ArrayList; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class CustomerManager { + + private ArrayList customers = new ArrayList<>(); + + public void addCustomer (String name, int pin, int customerID) { + + customers.add(new Customer (name, pin, customerID)); + + } + + public Customer getCustomer (int customerID) { + + for (Customer matchingCustomer: customers) { + if (matchingCustomer.getCustomerID() == customerID) { + return matchingCustomer; + } + + } + return null; + } +} diff --git a/src/main/java/crawley/james/project2atm/Display.java b/src/main/java/crawley/james/project2atm/Display.java new file mode 100644 index 0000000..15031b5 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/Display.java @@ -0,0 +1,111 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class Display { + + public void printWelcomeScreen () { + + System.out.println("Welcome!\nPress 1 for for new customer." + + "\nPress 2 for returning customer.\nPress 3 to Exit."); + + } + + public void printNewCustomerMenu () { + + System.out.println("Enter name: "); + System.out.println("Enter PIN: "); + + } + + public void printSuccessfulCreation (String newCustOrAcct, int ID) { + + System.out.println("Account created.\nYour " + newCustOrAcct + " ID is: " + ID); + } + + public void createAccountPrompt () { + + System.out.println("Enter initial balance: "); + } + + public void printLogin () { + + System.out.println("Enter ID: "); + System.out.println("Enter PIN: "); + + } + + public void invalidLoginMessage () { + + System.out.println("Error: invalid login info."); + + } + + public void printReturningCustomerMenu () { + + System.out.println("Press 1 to Open an account.\nPress 2 to Close and account.\nPress 3 to deposit." + + "\nPress 4 to withdrawal.\nPress 5 to transfer.\nPress 6 to get a list of transactions." + + "\nPress 7 to logout."); + + } + + public void closeAccountMessage (int closedMessageCase) { + + switch (closedMessageCase) { + case 0: + System.out.println("Error: cannot close account with balance."); + break; + case 1: + System.out.println("Error: invalid account ID."); + break; + case 2: + System.out.println("Account closed successfully."); + break; + + } + } + + public void closeAccountPrompt () { + + System.out.println("Input ID of account to close: "); + + } + + public void printAccountTypeOptions () { + + System.out.println("Press 1 to for a checking account.\nPress 2 for a savings account." + + "\nPress 3 for an investment account"); + } + + public void transactionPrompt (String transactionType) { + + System.out.println("Enter account ID: \nEnter amount to " + transactionType + ": "); + + } + + public void transactionPrompt () { + + System.out.println("Enter from account ID: \nEnter to account ID: \nEnter amount to transfer: "); + + } + + public void transactionErrorMessage () { + + System.out.println("Error: invalid account number."); + + } + + public void transactionSuccessMessage (double balance) { + + System.out.println("Your new balance is: $" + balance); + + } + + public void printOptionErrorMessage () { + + System.out.println("Invalid option"); + + } + +} diff --git a/src/main/java/crawley/james/project2atm/Transaction.java b/src/main/java/crawley/james/project2atm/Transaction.java new file mode 100644 index 0000000..c3939d6 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/Transaction.java @@ -0,0 +1,63 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class Transaction { + + public enum TransactionType {WITHDRAWAL, DEPOSIT, TRANSFER;} + + private TransactionType transactionType; + private double amount; + private int customerID; + private int fromAccountNumber; + private int toAccountNumber; + + public Transaction (TransactionType transactionType, int customerID, int accountNumber, double amount) { + + this.transactionType = transactionType; + this.customerID = customerID; + fromAccountNumber = accountNumber; + this.amount = amount; + + } + + public Transaction (TransactionType transactionType, int customerID, int fromAccountNumber, int toAccountNumber, double amount) { + + this.transactionType = transactionType; + this.customerID = customerID; + this.fromAccountNumber = fromAccountNumber; + this.toAccountNumber = toAccountNumber; + this.amount = amount; + + + } + + public int getFromAccountNumber () { + + return fromAccountNumber; + } + + public int getToAccountNumber () { + + return toAccountNumber; + } + + public double getAmount () { + + return amount; + } + + public TransactionType getTransactionType () { + + return transactionType; + } + + public int getCustomerID () { + + return customerID; + + } + + +} diff --git a/src/main/java/crawley/james/project2atm/TransactionManager.java b/src/main/java/crawley/james/project2atm/TransactionManager.java new file mode 100644 index 0000000..2734af0 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/TransactionManager.java @@ -0,0 +1,76 @@ +package crawley.james.project2atm; + +import java.util.ArrayList; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class TransactionManager { + + private ArrayList transactions = new ArrayList<>(); + + public void addTransaction (Transaction.TransactionType transactionType, int customerID, int accountNumber, double amount) { + + transactions.add(0, new Transaction(transactionType, customerID, accountNumber, amount)); + + } + + public void addTransaction (int customerID, int fromAccountNumber, int toAccountNumber, double amount) { + + transactions.add(0, new Transaction(Transaction.TransactionType.TRANSFER, customerID, fromAccountNumber, toAccountNumber, amount)); + + } + + public void printTransactions (int customerID) { + + System.out.println(getTransactions(customerID)); + + } + + public String getTransactions (int customerID) { + + String transactionList = ""; + for (Transaction transaction : transactions) { + if (transaction.getCustomerID() == customerID) { + transactionList += getProperTransactionList(transaction); + } + } + + return transactionList; + + } + + private boolean isTransfer (Transaction transaction) { + + return transaction.getTransactionType().equals(Transaction.TransactionType.TRANSFER); + + } + + private String transferToString (Transaction transaction) { + + return "Customer: " + transaction.getCustomerID() + ", From Account: " + + transaction.getFromAccountNumber() + ", To Account: " + + transaction.getToAccountNumber() + ", " + + transaction.getTransactionType() + ": $" + transaction.getAmount() + "\n"; + + } + + private String depositOrWithdrawalToString (Transaction transaction) { + + return "Customer: " + transaction.getCustomerID() + ", Account: " + + transaction.getFromAccountNumber() + ", " + transaction.getTransactionType() + + ": $" + transaction.getAmount() + "\n"; + + } + + private String getProperTransactionList (Transaction transaction) { + + if (isTransfer(transaction)) { + return transferToString(transaction); + } else { + return depositOrWithdrawalToString(transaction); + } + + } + +} diff --git a/src/main/java/crawley/james/project2atm/UserInputHandler.java b/src/main/java/crawley/james/project2atm/UserInputHandler.java new file mode 100644 index 0000000..fba6f42 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/UserInputHandler.java @@ -0,0 +1,43 @@ +package crawley.james.project2atm; + +import java.util.InputMismatchException; +import java.util.Scanner; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class UserInputHandler { + + private Scanner scanner = new Scanner(System.in); + + public int getUserInt () { + + try { + return scanner.nextInt(); + } catch (InputMismatchException e) { + System.out.println("Error: Please input a number"); + scanner.nextLine(); + return 0; + } + } + + public double getUserDouble () { + + try { + return scanner.nextDouble(); + } catch (InputMismatchException e) { + System.out.println("Error: Please input a number"); + scanner.nextLine(); + return 0; + } + + } + + public String getUserString() { + + return scanner.next(); + + } +} + + diff --git a/src/main/java/crawley/james/project2atm/UserInputHandlerDummy.java b/src/main/java/crawley/james/project2atm/UserInputHandlerDummy.java new file mode 100644 index 0000000..f788673 --- /dev/null +++ b/src/main/java/crawley/james/project2atm/UserInputHandlerDummy.java @@ -0,0 +1,43 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class UserInputHandlerDummy extends UserInputHandler { + + private int[] userInts; + private double[] userDoubles; + private String[] userStrings; + private int intIndex; + private int doubleIndex; + private int stringIndex; + + public UserInputHandlerDummy (int[] userInts, double[] userDoubles, String[] userStrings) { + + this.userInts = userInts; + this.userDoubles = userDoubles; + this.userStrings = userStrings; + + } + + @Override + public int getUserInt () { + + return userInts[++intIndex]; + + } + + @Override + public double getUserDouble () { + + return userDoubles[++doubleIndex]; + + } + + @Override + public String getUserString() { + + return userStrings[++stringIndex]; + + } +} diff --git a/src/main/java/crawley/james/project2atm/project2atm.java b/src/main/java/crawley/james/project2atm/project2atm.java new file mode 100644 index 0000000..e35f3ec --- /dev/null +++ b/src/main/java/crawley/james/project2atm/project2atm.java @@ -0,0 +1,13 @@ +package crawley.james.project2atm; + +/** + * Created by jamescrawley on 9/17/16. + */ +public class project2atm { + + public static void main (String[] args) { + + ATM atm = new ATM(); + atm.startATM(); + } +} diff --git a/src/test/java/crawley/james/project2atm/ATMTest.java b/src/test/java/crawley/james/project2atm/ATMTest.java new file mode 100644 index 0000000..fd35e7a --- /dev/null +++ b/src/test/java/crawley/james/project2atm/ATMTest.java @@ -0,0 +1,127 @@ +package crawley.james.project2atm; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ATMTest { + + @Test + public void createAccountTest () { + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + + assertNotNull("An account should be created.", atm.getAccountManager().getAccount(1, 1)); + } + + @Test + public void createCustomerTest () { + ATM atm = new ATM(); + atm.createCustomer("William Williams", 1234); + + assertNotNull("A customer should have been created.", atm.getCustomerManager().getCustomer(1)); + } + + @Test + public void closeAccountWithNoBalanceTest () { + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 0); + atm.closeAccount(1, 1); + + assertNull("The account should have been closed.", atm.getAccountManager().getAccount(1, 1)); + + } + + @Test + public void closeAccountWithBalanceTest () { + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + atm.closeAccount(1, 1); + + assertNotNull("The account should not have been closed.", atm.getAccountManager().getAccount(1, 1)); + + } + + @Test + public void verifyCorrectLoginTest () { + + ATM atm = new ATM(); + atm.createCustomer("William Williams", 1234); + + assert(atm.verifyLoginInfo(1, 1234)); + + } + + @Test + public void verifyIncorrectLoginTest () { + + ATM atm = new ATM(); + atm.createCustomer("William Williams", 1234); + + assert(!atm.verifyLoginInfo(1, 1235)); + + } + + @Test + public void depositTest () { + + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + atm.setCurrentUser(1); + atm.deposit(1, 50); + + assertEquals("The balance should be $150", 150, atm.getAccountManager().getAccount(1, 1).getBalance(), 0); + + } + + @Test + public void withdrawalTest () { + + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + atm.setCurrentUser(1); + atm.withdrawals(1, 50); + + assertEquals("The balance should be $50", 50, atm.getAccountManager().getAccount(1, 1).getBalance(), 0); + + } + + @Test + public void transferTest () { + + ATM atm = new ATM(); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + atm.createAccount(Account.AccountType.SAVINGS, 1, 2, 100); + atm.setCurrentUser(1); + atm.transfer(1, 2, 50); + + assertEquals("The balance should be $50", 50, atm.getAccountManager().getAccount(1, 1).getBalance(), 0); + + } + + @Test + public void transactionTest () { + + ATM atm = new ATM(); + atm.createCustomer("William Williams", 1234); + atm.createAccount(Account.AccountType.SAVINGS, 1, 1, 100); + atm.setCurrentUser(1); + atm.withdrawals(1, 50); + atm.deposit(1, 20); + + String expected = "Customer: 1, Account: 1, DEPOSIT: $20.0\n" + + "Customer: 1, Account: 1, WITHDRAWAL: $50.0\n"; + + assertEquals("Customer 1 should have recent transactions on Account 1 " + + "for depositing $20 and withdrawaling $50 in order of most recent to " + + "least recent.", expected, atm.getTransactionManager().getTransactions(1)); + + } +} diff --git a/src/test/java/crawley/james/project2atm/AccountManagerTest.java b/src/test/java/crawley/james/project2atm/AccountManagerTest.java new file mode 100644 index 0000000..0c58b9e --- /dev/null +++ b/src/test/java/crawley/james/project2atm/AccountManagerTest.java @@ -0,0 +1,36 @@ +package crawley.james.project2atm; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class AccountManagerTest { + + AccountManager accountManager = new AccountManager(); + + @Test + public void addAccountTest () { + + accountManager.addAccount(Account.AccountType.SAVINGS, 100, 12, 1); + assertNotNull(accountManager.getAccount(1, 12)); + + } + + @Test + public void deleteAccountTest () { + + accountManager.addAccount(Account.AccountType.SAVINGS, 0, 12, 1); + accountManager.deleteAccount(1, 12); + assertNull(accountManager.getAccount(1, 12)); + + } + +} diff --git a/src/test/java/crawley/james/project2atm/AccountTest.java b/src/test/java/crawley/james/project2atm/AccountTest.java new file mode 100644 index 0000000..382c457 --- /dev/null +++ b/src/test/java/crawley/james/project2atm/AccountTest.java @@ -0,0 +1,48 @@ +package crawley.james.project2atm; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class AccountTest { + + + Account account = new Account(Account.AccountType.SAVINGS, 100, 12, 1); + + @Test + public void balanceTest () { + + + assertEquals("The balance should be $100", 100, account.getBalance(), 0); + } + + @Test + public void accountTypeTest () { + + assertEquals("The type should be SAVINGS", Account.AccountType.SAVINGS, account.getAccountType()); + } + + @Test + public void customerIDTest () { + + assertEquals("The the Customer ID should be 12", 12, account.getCustomerID(), 0); + + } + + @Test + public void accountNumberTest () { + + assertEquals("The account number should be 1", 1, account.getAccountNumber()); + + } + + @Test + public void interestRateTest () { + + assertEquals("The interest rate should be", 0.05, account.getInterestRate(), 0); + + } + +} diff --git a/src/test/java/crawley/james/project2atm/CustomerManagerTest.java b/src/test/java/crawley/james/project2atm/CustomerManagerTest.java new file mode 100644 index 0000000..aecf9fd --- /dev/null +++ b/src/test/java/crawley/james/project2atm/CustomerManagerTest.java @@ -0,0 +1,18 @@ +package crawley.james.project2atm; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class CustomerManagerTest { + + @Test + public void testAddCustomers () { + CustomerManager customerManager = new CustomerManager(); + customerManager.addCustomer("William Williams", 1784, 1); + assertNotNull("The customer should have been added to the list.", customerManager.getCustomer(1)); + + } +} diff --git a/src/test/java/crawley/james/project2atm/CustomerTest.java b/src/test/java/crawley/james/project2atm/CustomerTest.java new file mode 100644 index 0000000..3c73d18 --- /dev/null +++ b/src/test/java/crawley/james/project2atm/CustomerTest.java @@ -0,0 +1,41 @@ +package crawley.james.project2atm; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CustomerTest { + + + + @Test + public void customerNameTest () { + Customer customer = new Customer("William Williams", 1784, 1); + + assertEquals("The name should be William Williams.", "William Williams", customer.getName()); + + } + + @Test + public void customerIDTest () { + Customer customer = new Customer("William Williams", 1784, 1); + + assertEquals("The ID should be 1", 1, customer.getCustomerID()); + + } + + @Test + public void customerPINTest () { + Customer customer = new Customer("William Williams", 1784, 1); + + assertEquals("The PIN should be 1784.", 1784, customer.getPin()); + + } +} diff --git a/src/test/java/crawley/james/project2atm/TransactionManagerTest.java b/src/test/java/crawley/james/project2atm/TransactionManagerTest.java new file mode 100644 index 0000000..3a0e04d --- /dev/null +++ b/src/test/java/crawley/james/project2atm/TransactionManagerTest.java @@ -0,0 +1,31 @@ +package crawley.james.project2atm; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class TransactionManagerTest { + + @Test + public void addDepositOrWithdrawalTest () { + + TransactionManager transactionManager = new TransactionManager(); + transactionManager.addTransaction(Transaction.TransactionType.DEPOSIT, 12, 1, 50); + + assertEquals("The customer ID should be 12, ID 1 and amount +$50.", "Customer: 12, Account: 1, DEPOSIT: $50.0\n", + transactionManager.getTransactions(12)); + } + + @Test + public void addTransferTest () { + + TransactionManager transactionManager = new TransactionManager(); + transactionManager.addTransaction(12, 1, 2, 50); + + assertEquals("The customer ID should be 12, From ID 1, To ID and amount $50.", "Customer: 12, From Account: 1, To Account: 2, TRANSFER: $50.0\n", + transactionManager.getTransactions(12)); + + } +} diff --git a/src/test/java/crawley/james/project2atm/TransactionTest.java b/src/test/java/crawley/james/project2atm/TransactionTest.java new file mode 100644 index 0000000..8fd19dc --- /dev/null +++ b/src/test/java/crawley/james/project2atm/TransactionTest.java @@ -0,0 +1,47 @@ +package crawley.james.project2atm; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Created by jamescrawley on 9/16/16. + */ +public class TransactionTest { + + @Test + public void getFromAccountNumberTest () { + + Transaction transaction = new Transaction(Transaction.TransactionType.WITHDRAWAL, 12, 1, 100); + + assertEquals("The account number should be 1", 1, transaction.getFromAccountNumber()); + + } + + @Test + public void getToAccountNumberTest () { + + Transaction transaction = new Transaction(Transaction.TransactionType.WITHDRAWAL, 12, 1, 2, 100); + + assertEquals("The account number should be 2", 2, transaction.getToAccountNumber()); + + } + + @Test + public void getTransactionTypeTest () { + + Transaction transaction = new Transaction(Transaction.TransactionType.WITHDRAWAL, 12, 1, 100); + + assertEquals("The transaction type should be WITHDRAWAL", Transaction.TransactionType.WITHDRAWAL, + transaction.getTransactionType()); + + } + + @Test + public void getAmountTest () { + + Transaction transaction = new Transaction(Transaction.TransactionType.WITHDRAWAL, 12, 1, 100); + + assertEquals("The the amount should be $100", 100, transaction.getAmount(), 0); + + } +} diff --git a/target/classes/crawley/james/project2atm/ATM.class b/target/classes/crawley/james/project2atm/ATM.class new file mode 100644 index 0000000..1906073 Binary files /dev/null and b/target/classes/crawley/james/project2atm/ATM.class differ diff --git a/target/classes/crawley/james/project2atm/Account$1.class b/target/classes/crawley/james/project2atm/Account$1.class new file mode 100644 index 0000000..a99b4ca Binary files /dev/null and b/target/classes/crawley/james/project2atm/Account$1.class differ diff --git a/target/classes/crawley/james/project2atm/Account$AccountType.class b/target/classes/crawley/james/project2atm/Account$AccountType.class new file mode 100644 index 0000000..fe9da00 Binary files /dev/null and b/target/classes/crawley/james/project2atm/Account$AccountType.class differ diff --git a/target/classes/crawley/james/project2atm/Account.class b/target/classes/crawley/james/project2atm/Account.class new file mode 100644 index 0000000..620a3a3 Binary files /dev/null and b/target/classes/crawley/james/project2atm/Account.class differ diff --git a/target/classes/crawley/james/project2atm/AccountManager.class b/target/classes/crawley/james/project2atm/AccountManager.class new file mode 100644 index 0000000..4e8bb4f Binary files /dev/null and b/target/classes/crawley/james/project2atm/AccountManager.class differ diff --git a/target/classes/crawley/james/project2atm/Customer.class b/target/classes/crawley/james/project2atm/Customer.class new file mode 100644 index 0000000..d82aeac Binary files /dev/null and b/target/classes/crawley/james/project2atm/Customer.class differ diff --git a/target/classes/crawley/james/project2atm/CustomerManager.class b/target/classes/crawley/james/project2atm/CustomerManager.class new file mode 100644 index 0000000..ecef7a3 Binary files /dev/null and b/target/classes/crawley/james/project2atm/CustomerManager.class differ diff --git a/target/classes/crawley/james/project2atm/Display.class b/target/classes/crawley/james/project2atm/Display.class new file mode 100644 index 0000000..258d07b Binary files /dev/null and b/target/classes/crawley/james/project2atm/Display.class differ diff --git a/target/classes/crawley/james/project2atm/Transaction$TransactionType.class b/target/classes/crawley/james/project2atm/Transaction$TransactionType.class new file mode 100644 index 0000000..a61c9ed Binary files /dev/null and b/target/classes/crawley/james/project2atm/Transaction$TransactionType.class differ diff --git a/target/classes/crawley/james/project2atm/Transaction.class b/target/classes/crawley/james/project2atm/Transaction.class new file mode 100644 index 0000000..8b76db4 Binary files /dev/null and b/target/classes/crawley/james/project2atm/Transaction.class differ diff --git a/target/classes/crawley/james/project2atm/TransactionManager.class b/target/classes/crawley/james/project2atm/TransactionManager.class new file mode 100644 index 0000000..4d80f41 Binary files /dev/null and b/target/classes/crawley/james/project2atm/TransactionManager.class differ diff --git a/target/classes/crawley/james/project2atm/UserInputHandler.class b/target/classes/crawley/james/project2atm/UserInputHandler.class new file mode 100644 index 0000000..98363d1 Binary files /dev/null and b/target/classes/crawley/james/project2atm/UserInputHandler.class differ diff --git a/target/classes/crawley/james/project2atm/UserInputHandlerDummy.class b/target/classes/crawley/james/project2atm/UserInputHandlerDummy.class new file mode 100644 index 0000000..0297b0b Binary files /dev/null and b/target/classes/crawley/james/project2atm/UserInputHandlerDummy.class differ diff --git a/target/classes/crawley/james/project2atm/project2atm.class b/target/classes/crawley/james/project2atm/project2atm.class new file mode 100644 index 0000000..cb70a7e Binary files /dev/null and b/target/classes/crawley/james/project2atm/project2atm.class differ diff --git a/target/test-classes/crawley/james/project2atm/ATMTest.class b/target/test-classes/crawley/james/project2atm/ATMTest.class new file mode 100644 index 0000000..493b106 Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/ATMTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/AccountManagerTest.class b/target/test-classes/crawley/james/project2atm/AccountManagerTest.class new file mode 100644 index 0000000..2c30909 Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/AccountManagerTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/AccountTest.class b/target/test-classes/crawley/james/project2atm/AccountTest.class new file mode 100644 index 0000000..089785a Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/AccountTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/CustomerManagerTest.class b/target/test-classes/crawley/james/project2atm/CustomerManagerTest.class new file mode 100644 index 0000000..29b777a Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/CustomerManagerTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/CustomerTest.class b/target/test-classes/crawley/james/project2atm/CustomerTest.class new file mode 100644 index 0000000..7485145 Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/CustomerTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/TransactionManagerTest.class b/target/test-classes/crawley/james/project2atm/TransactionManagerTest.class new file mode 100644 index 0000000..dead931 Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/TransactionManagerTest.class differ diff --git a/target/test-classes/crawley/james/project2atm/TransactionTest.class b/target/test-classes/crawley/james/project2atm/TransactionTest.class new file mode 100644 index 0000000..3e7d66e Binary files /dev/null and b/target/test-classes/crawley/james/project2atm/TransactionTest.class differ