From d17066420781ba04a981b0f863c619d2ed5f7082 Mon Sep 17 00:00:00 2001 From: kelly Date: Fri, 12 Mar 2021 22:07:39 -0500 Subject: [PATCH 01/28] Initial commit: setting up User class --- src/main/java/User.java | 29 +++++++++++++++++++++++++++++ src/main/test/UserTest.java | 9 +++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/User.java create mode 100644 src/main/test/UserTest.java diff --git a/src/main/java/User.java b/src/main/java/User.java new file mode 100644 index 0000000..b08d9d1 --- /dev/null +++ b/src/main/java/User.java @@ -0,0 +1,29 @@ + + + + +public class User { + + public String userName; + private String passWord; + public Account[] account; + + + // default constructor + public User() { + + + } + + // + + + + + + + + + + +} diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java new file mode 100644 index 0000000..a0b7a17 --- /dev/null +++ b/src/main/test/UserTest.java @@ -0,0 +1,9 @@ + + + + + + +// Test the expected User class from ATM. +public class UserTest { +} From f19ec331f50771e20bb21b0fa2c5be9ff385ea13 Mon Sep 17 00:00:00 2001 From: kelly Date: Fri, 12 Mar 2021 22:57:08 -0500 Subject: [PATCH 02/28] fleshed out constructors and defined method signatures. method bodies not completed --- src/main/java/User.java | 54 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index b08d9d1..42c05cc 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,21 +1,67 @@ +/* +Questions: +1. instance field password - access modifier for this private? if private, do we need a getter for this? +2. Constructors - + 2.1 a constructor that sets up a user with just their userName & password.. can make a user and not + necessarily need to assign them an account right away. + 2.2 should default constructor create empty accounts array of specified length? what would be the use + in that? +3. exceptions - how to set up? intelliJ interface different from the images from Dolio +4. Do we need to set up an account number that has a limit on length? uniformity with account number properties? + */ + + + + + public class User { public String userName; - private String passWord; - public Account[] account; + private String passWord; // *** access modifier for this??? if private, do we need a getter for this? + public Account[] accounts; + // CONSTRUCTORS + // default constructor - public User() { + public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? + Account[] accounts = new Account[30], // <- length of array? + + + } + + // Constructor for user with name, password, and account + public User(String userName, String passWord) { + this.userName = userName; + this.passWord = passWord; + } + // Constructor for user with name, password, and account + public User(String userName, String passWord, Account[] accounts) { + this.userName = userName; + this.passWord = passWord; + this.accounts = accounts; } - // + + // METHODS + + public void setUserName() {} + + private void setPassWord() {} // *** access modifier for this??? + + public void addAccount() {} + + public void removeAccount() {} + + + +} From f957aad55a88d4f6797089916ea6cc20aa2f83dc Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Fri, 12 Mar 2021 23:31:31 -0500 Subject: [PATCH 03/28] added method test signature definitions to UserTest class --- pom.xml | 8 ++++++ src/main/java/User.java | 22 ++++++++--------- src/main/test/AccountTest.java | 1 + src/main/test/UserTest.java | 45 ++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 9901415..7ecf8bc 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,14 @@ io.zipcoder project-2-atm 1.0-SNAPSHOT + + + org.testng + testng + RELEASE + test + + \ No newline at end of file diff --git a/src/main/java/User.java b/src/main/java/User.java index 42c05cc..580a894 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -8,7 +8,10 @@ 2.2 should default constructor create empty accounts array of specified length? what would be the use in that? 3. exceptions - how to set up? intelliJ interface different from the images from Dolio -4. Do we need to set up an account number that has a limit on length? uniformity with account number properties? +4. JUnit testing - how to configure? +5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? +6. Is the return of username a string? + */ @@ -29,12 +32,12 @@ public class User { // default constructor public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? - Account[] accounts = new Account[30], // <- length of array? + Account[] accounts = new Account[30]; // <- length of array? } - // Constructor for user with name, password, and account + // Constructor for user with name & password public User(String userName, String passWord) { this.userName = userName; this.passWord = passWord; @@ -55,21 +58,16 @@ public void setUserName() {} private void setPassWord() {} // *** access modifier for this??? + public String getUserName() { // *** return type for this? + return userName; + } + public void addAccount() {} public void removeAccount() {} - } - - - - - - - -} diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java index cbea4ad..cd6d7e4 100644 --- a/src/main/test/AccountTest.java +++ b/src/main/test/AccountTest.java @@ -2,6 +2,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.testng.annotations.Test; import static org.junit.Assert.assertEquals; diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index a0b7a17..7f3ffff 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -5,5 +5,50 @@ // Test the expected User class from ATM. + +import org.testng.annotations.Test; + public class UserTest { + + + @Test // tests default constructor + public void nulleryConstructorTest() {} + + @Test // tests default constructor + public void nulleryConstructorTestNeg() {} + + @Test // Constructor for user with name & password + public void constructorUserNamePWTest() {} + + @Test // Constructor for user with name & password + public void constructorUserNamePWTestNeg() {} + + @Test // Constructor for user with name, password & accounts array + public void constructorUserNamePWAcctsTest() {} + + @Test // Constructor for user with name, password & accounts array + public void constructorUserNamePWAcctsTestNeg() {} + + + + + + + + + + + + + + + + + + + + + + + } From a84a8dd6d29468fb4e4aa4fc8ffd3cd4be8dc22e Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sat, 13 Mar 2021 00:07:54 -0500 Subject: [PATCH 04/28] checkpointing - some method bodies complete, all test method signatures declared --- src/main/java/User.java | 40 ++++++++++++++++++++++----- src/main/test/UserTest.java | 54 ++++++++++++++++++++++++++++++++++--- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index 580a894..08b00e0 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -9,8 +9,11 @@ in that? 3. exceptions - how to set up? intelliJ interface different from the images from Dolio 4. JUnit testing - how to configure? -5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? +5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? account number as int data type? 6. Is the return of username a string? +7. Do we need to set up a get password method? +8. Do we need a getter for Accounts[] array of user's accounts? +9. ***** Do we need to use a map for username and passwords? **** */ @@ -31,7 +34,7 @@ public class User { // CONSTRUCTORS // default constructor - public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? + public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? Account[] accounts = new Account[30]; // <- length of array? @@ -54,17 +57,42 @@ public User(String userName, String passWord, Account[] accounts) { // METHODS - public void setUserName() {} + // sets userName if none assigned at construction, else resets username + public void setUserName() { + this.userName = userName; + } - private void setPassWord() {} // *** access modifier for this??? + // sets password if none assigned at construction, else resets password + private void setPassWord() { // *** access modifier for this??? + this.passWord = passWord; + } + // returns username as string public String getUserName() { // *** return type for this? return userName; } - public void addAccount() {} + // returns password as string + private String getPassWord() { // *** access modifier? + return passWord; + } - public void removeAccount() {} + // adds account to end of user's account array + public void addAccount(Account[] account, accountNumber) { + for (Account[] element : accounts) { + int i = 0; + if (accounts[i] == null) { + accounts += accountNumber; + } + } + } + + // removes account from specified index of user's account array + public void removeAccount(int accountNumber) {} + + public Account[] getAccounts() { + return accounts; + } } diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index 7f3ffff..b62e3a7 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -17,18 +17,64 @@ public void nulleryConstructorTest() {} @Test // tests default constructor public void nulleryConstructorTestNeg() {} - @Test // Constructor for user with name & password + @Test // tests constructor for user with name & password public void constructorUserNamePWTest() {} - @Test // Constructor for user with name & password + @Test // tests constructor for user with name & password public void constructorUserNamePWTestNeg() {} - @Test // Constructor for user with name, password & accounts array + @Test // tests constructor for user with name, password & accounts array public void constructorUserNamePWAcctsTest() {} - @Test // Constructor for user with name, password & accounts array + @Test // tests constructor for user with name, password & accounts array public void constructorUserNamePWAcctsTestNeg() {} + @Test + public void setUserNameTest() {} + + @Test + public void setUserNameTestNeg() {} + + @Test + public void getUserNameTest() {} + + @Test + public void getUserNameTestNeg() {} + + @Test + public void setPasswordTest() {} + + @Test + public void setPasswordTestNeg() {} + + @Test + public void getPasswordTest() {} + + @Test + public void getPasswordTestNeg() {} + + @Test + public void getAccountsArrayTest() {} + + @Test + public void getAccountsArrayTestNeg() {} + + @Test + public void addAccountTest() {} + + @Test + public void addAccountTestNeg() {} + + @Test + public void removeAccountTest() {} + + @Test + public void removeAccountTestNeg() {} + + + + + From 49509a706b8cc83274d2214eda310b18609d707a Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sat, 13 Mar 2021 01:14:43 -0500 Subject: [PATCH 05/28] all method bodies of User class complete --- src/main/java/User.java | 40 +++++++++++++---------- src/main/test/UserTest.java | 63 ++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index 08b00e0..3e9291d 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,3 +1,5 @@ +import java.util.Arrays; + /* Questions: @@ -10,20 +12,16 @@ 3. exceptions - how to set up? intelliJ interface different from the images from Dolio 4. JUnit testing - how to configure? 5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? account number as int data type? -6. Is the return of username a string? + 7. Do we need to set up a get password method? 8. Do we need a getter for Accounts[] array of user's accounts? 9. ***** Do we need to use a map for username and passwords? **** +10. Help with syntax for the add/remove functions of user's account array +11. Help with syntax for the get accounts array */ - - - - - - public class User { public String userName; @@ -68,7 +66,7 @@ private void setPassWord() { // *** access modifier for this??? } // returns username as string - public String getUserName() { // *** return type for this? + public String getUserName() { return userName; } @@ -77,20 +75,30 @@ private String getPassWord() { // *** access modifier? return passWord; } - // adds account to end of user's account array - public void addAccount(Account[] account, accountNumber) { + // adds new account to end of user's account array + public void addAccount(Account[] accounts, Account accountToAdd) { + int i = 0; for (Account[] element : accounts) { - int i = 0; - if (accounts[i] == null) { - accounts += accountNumber; - } + if (element[i] == null) { + element[i] += accountToAdd; // **** HELP W THE SYNTAX OF THIS METHOD *** + } i++; } } - // removes account from specified index of user's account array - public void removeAccount(int accountNumber) {} + // removes specified account from user's account array, replaces space in index with null + public void removeAccount(Account[] accounts, Account accountToRemove) { + int i = 0; + for (Account[] element : accounts) { // for each element in the User's array of their accounts, + // check to see if the value at i is equal to the account to remove + if (element[i] == accountToRemove) { // if the value at accounts[i] is equal to the account to remove, + element[i] = null; // replace the value at accounts[i] with null + } i++; + } + } + // returns accounts, prints accounts array to string public Account[] getAccounts() { + System.out.println(accounts.toString); // double check syntax on this one? return accounts; } diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index b62e3a7..7a4c652 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -12,68 +12,87 @@ public class UserTest { @Test // tests default constructor - public void nulleryConstructorTest() {} + public void nulleryConstructorTest() { + } @Test // tests default constructor - public void nulleryConstructorTestNeg() {} + public void nulleryConstructorTestNeg() { + } @Test // tests constructor for user with name & password - public void constructorUserNamePWTest() {} + public void constructorUserNamePWTest() { + } @Test // tests constructor for user with name & password - public void constructorUserNamePWTestNeg() {} + public void constructorUserNamePWTestNeg() { + } @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTest() {} + public void constructorUserNamePWAcctsTest() { + } @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTestNeg() {} + public void constructorUserNamePWAcctsTestNeg() { + } @Test - public void setUserNameTest() {} + public void setUserNameTest() { + } @Test - public void setUserNameTestNeg() {} + public void setUserNameTestNeg() { + } @Test - public void getUserNameTest() {} + public void getUserNameTest() { + } @Test - public void getUserNameTestNeg() {} + public void getUserNameTestNeg() { + } @Test - public void setPasswordTest() {} + public void setPasswordTest() { + } @Test - public void setPasswordTestNeg() {} + public void setPasswordTestNeg() { + } @Test - public void getPasswordTest() {} + public void getPasswordTest() { + } @Test - public void getPasswordTestNeg() {} + public void getPasswordTestNeg() { + } @Test - public void getAccountsArrayTest() {} + public void getAccountsArrayTest() { + } @Test - public void getAccountsArrayTestNeg() {} + public void getAccountsArrayTestNeg() { + } @Test - public void addAccountTest() {} + public void addAccountTest() { + } @Test - public void addAccountTestNeg() {} + public void addAccountTestNeg() { + } @Test - public void removeAccountTest() {} + public void removeAccountTest() { + } @Test - public void removeAccountTestNeg() {} - - + public void removeAccountTestNeg() { + } +} From 95b0229d8d940c524af4c540348dd5aa5df6b097 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sat, 13 Mar 2021 02:15:47 -0500 Subject: [PATCH 06/28] checkpointing: test class skeleton almost complete, need to write tests for contructors --- src/main/java/User.java | 32 +++--- src/main/test/UserTest.java | 212 ++++++++++++++++++++++++++++++------ 2 files changed, 195 insertions(+), 49 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index 3e9291d..0edc818 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -24,8 +24,8 @@ public class User { - public String userName; - private String passWord; // *** access modifier for this??? if private, do we need a getter for this? + public String username; + private String password; // *** access modifier for this??? if private, do we need a getter for this? public Account[] accounts; @@ -39,15 +39,15 @@ public User() { // <- should this constructor set up a } // Constructor for user with name & password - public User(String userName, String passWord) { - this.userName = userName; - this.passWord = passWord; + public User(String username, String password) { + this.username = username; + this.password = password; } // Constructor for user with name, password, and account - public User(String userName, String passWord, Account[] accounts) { - this.userName = userName; - this.passWord = passWord; + public User(String username, String password, Account[] accounts) { + this.username = username; + this.password = password; this.accounts = accounts; } @@ -56,23 +56,23 @@ public User(String userName, String passWord, Account[] accounts) { // METHODS // sets userName if none assigned at construction, else resets username - public void setUserName() { - this.userName = userName; + public void setUsername(String username) { + this.username = username; } // sets password if none assigned at construction, else resets password - private void setPassWord() { // *** access modifier for this??? - this.passWord = passWord; + private void setPassword(String password) { // *** access modifier for this??? + this.password = password; } // returns username as string - public String getUserName() { - return userName; + public String getUsername() { + return username; } // returns password as string - private String getPassWord() { // *** access modifier? - return passWord; + private String getPassword() { // *** access modifier? + return password; } // adds new account to end of user's account array diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index 7a4c652..24183d9 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -6,89 +6,235 @@ // Test the expected User class from ATM. +import org.testng.Assert; import org.testng.annotations.Test; public class UserTest { - @Test // tests default constructor - public void nulleryConstructorTest() { - } - - @Test // tests default constructor - public void nulleryConstructorTestNeg() { - } - - @Test // tests constructor for user with name & password - public void constructorUserNamePWTest() { - } - - @Test // tests constructor for user with name & password - public void constructorUserNamePWTestNeg() { - } - - @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTest() { - } - - @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTestNeg() { +// @Test // tests default constructor +// public void nulleryConstructorTest() { +// } +// +// @Test // tests default constructor +// public void nulleryConstructorTestNeg() { +// } +// +// @Test // tests constructor for user with name & password +// public void constructorUserNamePWTest() { +// } +// +// @Test // tests constructor for user with name & password +// public void constructorUserNamePWTestNeg() { +// } +// +// @Test // tests constructor for user with name, password & accounts array +// public void constructorUserNamePWAcctsTest() { +// } +// +// @Test // tests constructor for user with name, password & accounts array +// public void constructorUserNamePWAcctsTestNeg() { +// } + + @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method + // double check return is the new value you set it to, not the first argument that you + // passed in w/ get method + public void setUsernameTest() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String newUsername = "User02"; + testUser.setUsername(newUsername); + String actualUsername = testUser.getUsername(); + + Assert.assertEquals(actualUsername, newUsername); } @Test - public void setUserNameTest() { + public void setUsernameTestNeg() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String newUsername = "User02"; + testUser.setUsername(newUsername); + String actualUsername = testUser.getUsername(); + + Assert.assertEquals(actualUsername, newUsername); } - @Test - public void setUserNameTestNeg() { - } - - @Test + @Test // method returns username how to test: pass in username value, check to make sure username returned + // is same as what you passed in public void getUserNameTest() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String actualUsername = testUser.getUsername(); + + Assert.assertEquals(actualUsername, expectedUsername); } @Test public void getUserNameTestNeg() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String actualUsername = testUser.getUsername(); + + Assert.assertNotEquals(actualUsername, "unknown"); } - @Test + @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method + // double check return is the new value you set it to, not the first argument that you + // passed in w/ get method public void setPasswordTest() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String newPassword = testUser.setPassword(expectedPassword); + String actualPassword = testUser.getUsername(); + + Assert.assertEquals(actualPassword, newPassword); } @Test public void setPasswordTestNeg() { + String initialUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(initialUsername, expectedPassword); + String newPassword = testUser.setPassword(expectedPassword); + String actualPassword = testUser.getUsername(); + + Assert.assertNotEquals(actualPassword, initialUsername); } - @Test + @Test // method returns username how to test: pass in username value, check to make sure username returned + // is same as what you passed in public void getPasswordTest() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String actualPassword = testUser.getPassword(); + + Assert.assertEquals(actualPassword, expectedPassword); } @Test public void getPasswordTestNeg() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String actualPassword = testUser.getPassword(); + + Assert.assertNotEquals(actualPassword, "Unknown"); } - @Test + @Test // method returns user's array of accounts how to test: check to make sure accounts array returned + // (return as a string with .toString method) convert original accounts array to string + // matches original, passed in array make array use .toString method on it + // need accounts constructor to make multiple instances of accounts, pass into array, pass array into + // constructor of user public void getAccountsArrayTest() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3}; + String initialArrString = accountsArr.toString(); + User testUser = new User("User01", "password123", accountsArr); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertEquals(actualArrString, initialArrString); + } @Test public void getAccountsArrayTestNeg() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3}; + String initialArrString = accountsArr.toString(); + User testUser = new User("User01", "password123", accountsArr); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertNotEquals(actualArrString, "5"); } - @Test + @Test // method adds account to user's array of accounts how to test: check to make sure accounts array returns + // initial accounts array passed in + // (return as a string with .toString method) convert original accounts array to string + // matches original, passed in array make array use .toString method on it + // use .addAccount method, pass in account to add + // change output array to string, compare strings to strings + // save expected string to variable to pass in for expected assert type in your expected string + // need accounts constructor to make multiple instances of accounts, pass into array, pass array into + // constructor of user public void addAccountTest() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account account4 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3}; + String initialArrString = accountsArr.toString(); + User testUser = new User("User01", "password123", accountsArr); + testUser.addAccount(accounts, account4); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertEquals(actualArrString, initialArrString); } @Test public void addAccountTestNeg() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account account4 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3}; + String initialArrString = accountsArr.toString(); + User testUser = new User("User01", "password123", accountsArr); + testUser.addAccount(accounts, account4); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertNotEquals( actualArrString, 5); } - @Test + @Test // method adds account to user's array of accounts how to test: check to make sure accounts array returns + // initial accounts array passed in + // (return as a string with .toString method) convert original accounts array to string + // matches original, passed in array make array use .toString method on it + // use .addAccount method, pass in account to add + // change output array to string, compare strings to strings + // save expected string to variable to pass in for expected assert type in your expected string + // need accounts constructor to make multiple instances of accounts, pass into array, pass array into + // constructor of user public void removeAccountTest() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account account4 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3, account4}; + Account[] expectedArr = {account1, account3, account4}; + String expectedArrString = expectedArr + User testUser = new User("User01", "password123", accountsArr); + testUser.removeAccount(accounts, account2); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertEquals(actualArrString, expectedArrString); } @Test public void removeAccountTestNeg() { + Account account1 = new Account(accountNumber, availableBalance); + Account account2 = new Account(accountNumber, availableBalance); + Account account3 = new Account(accountNumber, availableBalance); + Account account4 = new Account(accountNumber, availableBalance); + Account[] accountsArr = {account1, account2, account3, account4}; + Account[] expectedArr = {account1, account3, account4}; + String expectedArrString = expectedArr + User testUser = new User("User01", "password123", accountsArr); + testUser.removeAccount(accounts, account2); + String actualArrString = accountsArr.toString(accountsArr.getAccounts()); + + Assert.assertNotEquals(actualArrString, 5); } From 0afe802122df1c113858ef1af66433d1d342dff2 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sat, 13 Mar 2021 02:42:52 -0500 Subject: [PATCH 07/28] fixed some syntax errors in the User test class --- src/main/java/User.java | 14 ++++---- src/main/test/UserTest.java | 70 ++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index 0edc818..dc06496 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,6 +1,3 @@ -import java.util.Arrays; - - /* Questions: 1. instance field password - access modifier for this private? if private, do we need a getter for this? @@ -18,6 +15,11 @@ 9. ***** Do we need to use a map for username and passwords? **** 10. Help with syntax for the add/remove functions of user's account array 11. Help with syntax for the get accounts array +12. need console class? manages console interactions. Create a console mock for testing + (provide scripted user input using this object) +13. persistence = the Dikstra 2 stack algorithm - implement? +14. users are authenticated with a password - generated or provided on user creation? + generated password created with default constructor? */ @@ -25,7 +27,7 @@ public class User { public String username; - private String password; // *** access modifier for this??? if private, do we need a getter for this? + public String password; // *** access modifier for this??? if private, do we need a getter for this? public Account[] accounts; @@ -61,7 +63,7 @@ public void setUsername(String username) { } // sets password if none assigned at construction, else resets password - private void setPassword(String password) { // *** access modifier for this??? + public void setPassword(String password) { // *** access modifier for this??? this.password = password; } @@ -71,7 +73,7 @@ public String getUsername() { } // returns password as string - private String getPassword() { // *** access modifier? + public String getPassword() { // *** access modifier? return password; } diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index 24183d9..072bb52 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -12,29 +12,34 @@ public class UserTest { -// @Test // tests default constructor -// public void nulleryConstructorTest() { -// } -// -// @Test // tests default constructor -// public void nulleryConstructorTestNeg() { -// } -// -// @Test // tests constructor for user with name & password -// public void constructorUserNamePWTest() { -// } -// -// @Test // tests constructor for user with name & password -// public void constructorUserNamePWTestNeg() { -// } -// -// @Test // tests constructor for user with name, password & accounts array -// public void constructorUserNamePWAcctsTest() { -// } -// -// @Test // tests constructor for user with name, password & accounts array -// public void constructorUserNamePWAcctsTestNeg() { -// } + @Test // tests default constructor + public void nulleryConstructorTest() { + } + + @Test // tests default constructor + public void nulleryConstructorTestNeg() { + } + + @Test // tests constructor for user with name & password + public void constructorUserNamePWTest() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + User testUser = new User(expectedUsername, expectedPassword); + String actualUsername = testUser.getUsername(); + String actualPassword = testUser.getPassword; + } + + @Test // tests constructor for user with name & password + public void constructorUserNamePWTestNeg() { + } + + @Test // tests constructor for user with name, password & accounts array + public void constructorUserNamePWAcctsTest() { + } + + @Test // tests constructor for user with name, password & accounts array + public void constructorUserNamePWAcctsTestNeg() { + } @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method // double check return is the new value you set it to, not the first argument that you @@ -64,7 +69,7 @@ public void setUsernameTestNeg() { @Test // method returns username how to test: pass in username value, check to make sure username returned // is same as what you passed in - public void getUserNameTest() { + public void getUsernameTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; User testUser = new User(expectedUsername, expectedPassword); @@ -74,7 +79,7 @@ public void getUserNameTest() { } @Test - public void getUserNameTestNeg() { + public void getUsernameTestNeg() { String expectedUsername = "User01"; String expectedPassword = "password123"; User testUser = new User(expectedUsername, expectedPassword); @@ -87,13 +92,14 @@ public void getUserNameTestNeg() { // double check return is the new value you set it to, not the first argument that you // passed in w/ get method public void setPasswordTest() { - String expectedUsername = "User01"; + String initialUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); - String newPassword = testUser.setPassword(expectedPassword); - String actualPassword = testUser.getUsername(); + User testUser = new User(initialUsername, expectedPassword); + testUser.setPassword("121212"); + String actualPassword = testUser.getPassword(); - Assert.assertEquals(actualPassword, newPassword); + + Assert.assertEquals(actualPassword, "121212"); } @Test @@ -101,8 +107,8 @@ public void setPasswordTestNeg() { String initialUsername = "User01"; String expectedPassword = "password123"; User testUser = new User(initialUsername, expectedPassword); - String newPassword = testUser.setPassword(expectedPassword); - String actualPassword = testUser.getUsername(); + testUser.setPassword("121212"); + String actualPassword = testUser.getPassword(); Assert.assertNotEquals(actualPassword, initialUsername); } From ece70e7568559ea769142cee0035176a9ff4bc29 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sat, 13 Mar 2021 11:11:15 -0500 Subject: [PATCH 08/28] attempting to push User class skeleton --- src/main/java/User.java | 4 ++++ src/main/test/UserTest.java | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/User.java b/src/main/java/User.java index dc06496..41f8926 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -59,21 +59,25 @@ public User(String username, String password, Account[] accounts) { // sets userName if none assigned at construction, else resets username public void setUsername(String username) { + this.username = username; } // sets password if none assigned at construction, else resets password public void setPassword(String password) { // *** access modifier for this??? this.password = password; + } // returns username as string public String getUsername() { + return username; } // returns password as string public String getPassword() { // *** access modifier? + return password; } diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index 072bb52..8b4c22f 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -26,7 +26,7 @@ public void constructorUserNamePWTest() { String expectedPassword = "password123"; User testUser = new User(expectedUsername, expectedPassword); String actualUsername = testUser.getUsername(); - String actualPassword = testUser.getPassword; + String actualPassword = testUser.getPassword; // *** finish writing this test body **** } @Test // tests constructor for user with name & password @@ -41,7 +41,7 @@ public void constructorUserNamePWAcctsTest() { public void constructorUserNamePWAcctsTestNeg() { } - @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method + @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method // double check return is the new value you set it to, not the first argument that you // passed in w/ get method public void setUsernameTest() { @@ -88,7 +88,7 @@ public void getUsernameTestNeg() { Assert.assertNotEquals(actualUsername, "unknown"); } - @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method + @Test // method sets/resets password how to test: create user, pass in pw arg, use set/reset method // double check return is the new value you set it to, not the first argument that you // passed in w/ get method public void setPasswordTest() { @@ -113,7 +113,7 @@ public void setPasswordTestNeg() { Assert.assertNotEquals(actualPassword, initialUsername); } - @Test // method returns username how to test: pass in username value, check to make sure username returned + @Test // method returns password how to test: pass in username value, check to make sure username returned // is same as what you passed in public void getPasswordTest() { String expectedUsername = "User01"; From 0e5b48a78c6e47565f0d6a3fc0a0a8a5f78deeca Mon Sep 17 00:00:00 2001 From: Monali Date: Sat, 13 Mar 2021 21:38:11 -0500 Subject: [PATCH 09/28] added two classes ATM and Account and deleted main --- pom.xml | 6 ++ src/main/java/ATM.java | 152 +++++++++++++++++++++++++++++++++++++ src/main/java/Account.java | 23 ++++++ src/main/java/Main.java | 9 --- 4 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 src/main/java/ATM.java create mode 100644 src/main/java/Account.java delete mode 100644 src/main/java/Main.java diff --git a/pom.xml b/pom.xml index 7ecf8bc..3fe1310 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,12 @@ RELEASE test + + org.junit.jupiter + junit-jupiter + RELEASE + compile + diff --git a/src/main/java/ATM.java b/src/main/java/ATM.java new file mode 100644 index 0000000..e42ed4d --- /dev/null +++ b/src/main/java/ATM.java @@ -0,0 +1,152 @@ +import java.text.NumberFormat; +import java.util.Scanner; +public class ATM { + public static void main(String[] args) { +// Create and instantiate checking Account objects + Account checking = new Account(); + checking.setType("Checking"); + checking.setBalance(0.00); + +// Create and instantiate checking Account objects + Account savings = new Account(); + savings.setType("Savings"); + savings.setBalance(0.00); + + + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + Scanner sc = new Scanner(System.in); + boolean session = true; + while (session) { +// Menu options for the user + System.out.print("\nATM Menu: \n \n" + + "1. Deposit Money \n" + + "2. Withdraw Money \n" + + "3. Transfer Funds \n" + + "4. Check Account Balance\n" + + "5. End Session\n \n" + + "Enter selection: "); + Integer selection = sc.nextInt(); + + if (selection <1 || selection >5){ + System.out.println("Error - Please enter correct option"); + } + + switch (selection) { +// case 1 handles the depositing of money + case 1: + System.out.print("Enter (1) for Savings or (2) for Checking: "); + Integer depAccount = sc.nextInt(); + +// Keeps track of which account to deposit money to - checking or saving + if (depAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.println("How much money would you like to deposit?"); + + Double deposit = sc.nextDouble(); + if (deposit < 0){ + System.out.println("Please enter amount greater than ZERO"); + }else { + savings.deposit(deposit); + System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + } + } else if (depAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.println("How much money would you like to deposit?"); + + Double deposit = sc.nextDouble(); + if (deposit < 0){ + System.out.println("Please enter amount greater than ZERO"); + }else { + checking.deposit(deposit); + System.out.println("\nChecking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + } + } + else{ + System.out.println("Please enter valid input (1 for Savings and 2 for Checking)"); + } + + break; +// case 2 handles the withdrawal of money + case 2: + System.out.print("\nEnter (1) for Savings or (2) for Checking: "); + Integer witAccount = sc.nextInt(); // Keeps track of which account to withdraw from + if (witAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.println("How much money would you like to withdraw?"); + + Double withdraw = sc.nextDouble(); + if (withdraw > savings.balance){ + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); + } + else { + savings.withdraw(withdraw); + System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + } + } + else if (witAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.println("How much money would you like to withdraw?"); + + Double withdraw = sc.nextDouble(); + if(withdraw > checking.balance){ + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); + } + else { + checking.withdraw(withdraw); + System.out.println("\nYour Checking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + } + } + break; +// case 3 handles the transfer of funds + case 3: + System.out.print("\nFrom which account do you wish to transfer funds from?, (1) for Savings or (2) for Checking: "); + Integer tranAccount = sc.nextInt(); + if (tranAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from Savings to Checking?: "); + + Double tranAmount = sc.nextDouble(); + if (tranAmount > savings.balance){ + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + } + else { + savings.withdraw(tranAmount); + checking.deposit(tranAmount); + + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); + } + } + else if (tranAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from Checking to Saving?: "); + + Double tranAmount = sc.nextDouble(); + if(tranAmount > checking.balance){ + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + } + else { + checking.withdraw(tranAmount); + savings.deposit(tranAmount); + + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Checking to Savings"); + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); + } + } + break; +// case 4 simply outputs the balances of both Checking and Savings accounts + case 4: + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); + break; +// case 5 breaks out of the (while) loop when the user is finished using the ATM + case 5: + session = false; + break; + } + } + System.out.println("\nThank you for banking with us! Have a nice time.\n"); + } +} diff --git a/src/main/java/Account.java b/src/main/java/Account.java new file mode 100644 index 0000000..9f3ccde --- /dev/null +++ b/src/main/java/Account.java @@ -0,0 +1,23 @@ +public class Account { + + String type; + double balance; + + + void setType(String accType) { + type = accType; + } + void setBalance(Double accBal) { + balance = accBal; + } + + void deposit(Double dep) { + balance = balance + dep; + } + void withdraw(Double wit) { + balance = balance - wit; + } + Double getBalance() { + return balance; + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index 05e41a9..0000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Created by iyasuwatts on 10/17/17. - */ -public class Main { - - public static void main(String[] args){ - - } -} From b579cf11e6487fada3364d51e623abae9c0e43c6 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 01:08:47 -0500 Subject: [PATCH 10/28] Created login/logout, create new account, welcome menu, & console --- pom.xml | 12 +++++ src/main/java/ATM.java | 73 +++++++++++++++++++++++++++ src/main/java/Console.java | 35 +++++++++++++ src/main/java/LogInScreen.java | 80 ++++++++++++++++++++++++++++++ src/main/java/Main.java | 3 +- src/main/java/User.java | 17 ++++--- src/main/test/ATMTest.java | 10 ++++ src/main/test/AccountTest.java | 3 +- src/main/test/ConsoleTest.java | 5 ++ src/main/test/LoginScreenTest.java | 8 +++ src/main/test/UserTest.java | 23 +-------- 11 files changed, 238 insertions(+), 31 deletions(-) create mode 100644 src/main/java/ATM.java create mode 100644 src/main/java/Console.java create mode 100644 src/main/java/LogInScreen.java create mode 100644 src/main/test/ATMTest.java create mode 100644 src/main/test/ConsoleTest.java create mode 100644 src/main/test/LoginScreenTest.java diff --git a/pom.xml b/pom.xml index 7ecf8bc..c4ae8fd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder project-2-atm 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + + + org.testng diff --git a/src/main/java/ATM.java b/src/main/java/ATM.java new file mode 100644 index 0000000..f13628e --- /dev/null +++ b/src/main/java/ATM.java @@ -0,0 +1,73 @@ +import java.util.Scanner; + +public class ATM { + + private Console c; + private Integer userInput; + private LogInScreen ls; + private boolean loggedIn; + private String currentUser; + + public ATM () { + this.c = new Console(); + this.ls = new LogInScreen(); + this.loggedIn = false; + this.currentUser = ""; + } + + public void printMenus() { + + while(true) { + if (this.loggedIn == false) { + this.printWelcomeMenu(); + + } else { + this.printUserMenu(); + } + } + + } + + public void printWelcomeMenu() { + System.out.println("WELCOME TO THE BANK OF ZIP CODE"); + System.out.println("LOCATED IN WILMINGTON, DELAWARE"); + System.out.println("PRESS 1 TO LOGIN"); + System.out.println("PRESS 2 IF YOU ARE A NEW USER"); + + this.userInput = c.getIntegerInput(); + + switch (userInput) { + case 1: + this.loggedIn = ls.validateLoginCredentials(); + this.currentUser = ls.getEnteredUserName(); + break; + case 2: + this.loggedIn = ls.createNewUserAccount(); + this.currentUser = ls.getEnteredUserName(); + break; + default: + System.out.println("Invalid input. Please select either 1 or 2."); + } + } + + public void printUserMenu() { + System.out.println("WELCOME " + this.currentUser); + System.out.println("USER MENU"); + System.out.println("1 - LogOut"); + + this.userInput = c.getIntegerInput(); + + switch (userInput) { + case 1: + this.loggedIn = false; + this.currentUser = ""; + this.printWelcomeMenu(); + break; + default: + System.out.println("Invalid input. Please select one of the listed options."); + break; + } + } +} + + diff --git a/src/main/java/Console.java b/src/main/java/Console.java new file mode 100644 index 0000000..6b437a4 --- /dev/null +++ b/src/main/java/Console.java @@ -0,0 +1,35 @@ +import java.util.Scanner; + +public class Console { + + public String getStringInput() { + Scanner scanner = new Scanner(System.in); + String userInput = scanner.nextLine(); + if (userInput.isEmpty()) { + System.out.println("Invalid Input!"); + userInput = scanner.nextLine(); + } + return userInput; + } + + public Integer getIntegerInput() { + Scanner scanner = new Scanner(System.in); + while(!scanner.hasNextInt()) { + System.out.println("Invalid Input!"); + scanner.next(); + } + int userInput = scanner.nextInt(); + return userInput; + } + + public Double getDoubleInput() { + Scanner scanner = new Scanner(System.in); + while(!scanner.hasNextDouble()) { + System.out.println("Invalid Input!"); + scanner.next(); + } + double userInput = scanner.nextDouble(); + return userInput; + } + +} diff --git a/src/main/java/LogInScreen.java b/src/main/java/LogInScreen.java new file mode 100644 index 0000000..8c22c16 --- /dev/null +++ b/src/main/java/LogInScreen.java @@ -0,0 +1,80 @@ +import java.util.HashMap; + +public class LogInScreen { + + Console c = new Console(); + private String enteredUserName; + private String enteredPassword; + private HashMap userNamePasswordMap; + + public LogInScreen() { + // FOR TESTING + this.userNamePasswordMap = new HashMap(); + this.userNamePasswordMap.put("TestAccount", "123"); + } + + public String getEnteredUserName() { + return this.enteredUserName; + } + + public void getUserName() { + System.out.println("Username:"); + this.enteredUserName = c.getStringInput(); + } + + public void getPassword() { + System.out.println("Password"); + this.enteredPassword = c.getStringInput(); + } + + public boolean validateUserNameExists() { + this.getUserName(); + return this.userNamePasswordMap.containsKey(this.enteredUserName); + } + + public boolean validatePasswordCorrect() { + this.getPassword(); + return this.userNamePasswordMap.get(this.enteredUserName).equals(this.enteredPassword); + } + + public boolean validateLoginCredentials() { + int attempts = 0; + while (attempts < 3) { + if(this.validateUserNameExists() == false) { + System.out.println("No such user exists."); + attempts += 1; + } else if (this.validatePasswordCorrect() == false) { + System.out.println("Password is incorrect."); + attempts += 1; + } else { + System.out.println("You are now logged in."); + return true; + } + } + + return false; + } + + public boolean createNewUserAccount() { + System.out.println("Enter your new username and password."); + int attempts = 0; + while (attempts < 3) { + if (this.validateUserNameExists() == false) { + getPassword(); + System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!"); + return true; + } else { + System.out.println("Username is already taken. Please select another."); + attempts += 1; + } + } + + return false; + } + + public void setUpUserAccount() { + this.userNamePasswordMap.put(this.enteredUserName, this.enteredPassword); + User newUser = new User(this.enteredUserName, this.enteredPassword); + } +} + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..1d4ec81 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,7 @@ public class Main { public static void main(String[] args){ - + ATM atm = new ATM(); + atm.printMenus(); } } diff --git a/src/main/java/User.java b/src/main/java/User.java index 41f8926..779f1dc 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -26,16 +26,16 @@ public class User { - public String username; - public String password; // *** access modifier for this??? if private, do we need a getter for this? - public Account[] accounts; + private String username; + private String password; // *** access modifier for this??? if private, do we need a getter for this? + //public Account[] accounts; // CONSTRUCTORS // default constructor public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? - Account[] accounts = new Account[30]; // <- length of array? + //Account[] accounts = new Account[30]; // <- length of array? } @@ -47,14 +47,14 @@ public User(String username, String password) { } // Constructor for user with name, password, and account - public User(String username, String password, Account[] accounts) { + public User(String username, String password /*Account[] accounts*/) { this.username = username; this.password = password; - this.accounts = accounts; + //this.accounts = accounts; } - +/* // METHODS // sets userName if none assigned at construction, else resets username @@ -108,8 +108,9 @@ public Account[] getAccounts() { return accounts; } - +*/ } + diff --git a/src/main/test/ATMTest.java b/src/main/test/ATMTest.java new file mode 100644 index 0000000..fd6cd73 --- /dev/null +++ b/src/main/test/ATMTest.java @@ -0,0 +1,10 @@ +import org.testng.annotations.Test; + +public class ATMTest { + + @Test + public void testGetInitialInput(){ + ATM atmTest = new ATM(); + atmTest.printWelcomeMenu(); + } +} diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java index cd6d7e4..a3c4ad1 100644 --- a/src/main/test/AccountTest.java +++ b/src/main/test/AccountTest.java @@ -1,4 +1,4 @@ - +/* import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -82,3 +82,4 @@ public void testA6() { } +*/ \ No newline at end of file diff --git a/src/main/test/ConsoleTest.java b/src/main/test/ConsoleTest.java new file mode 100644 index 0000000..c65607c --- /dev/null +++ b/src/main/test/ConsoleTest.java @@ -0,0 +1,5 @@ +public class ConsoleTest { + + + +} diff --git a/src/main/test/LoginScreenTest.java b/src/main/test/LoginScreenTest.java new file mode 100644 index 0000000..3d3b1fa --- /dev/null +++ b/src/main/test/LoginScreenTest.java @@ -0,0 +1,8 @@ +public class LoginScreenTest { + + public void testLoginScreen() { + LogInScreen ls = new LogInScreen(); + + + } +} diff --git a/src/main/test/UserTest.java b/src/main/test/UserTest.java index 8b4c22f..51eef4b 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserTest.java @@ -5,7 +5,7 @@ // Test the expected User class from ATM. - +/* import org.testng.Assert; import org.testng.annotations.Test; @@ -247,25 +247,6 @@ public void removeAccountTestNeg() { } - - - - - - - - - - - - - - - - - - - - } +*/ \ No newline at end of file From bdd4533f3ab3e9ba253867d6472bb274e44d77d2 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 10:01:20 -0400 Subject: [PATCH 11/28] Made some small changes --- README.md | 6 +++--- pom.xml | 2 +- src/main/java/Main.java | 4 ++-- src/main/java/{ATM.java => Menu.java} | 19 +++++++++++-------- src/main/java/User.java | 10 +++++----- .../{LogInScreen.java => UserManagement.java} | 15 +++++++++++---- src/main/test/ATMTest.java | 10 ---------- src/main/test/LoginScreenTest.java | 2 +- src/main/test/MenuTest.java | 10 ++++++++++ 9 files changed, 44 insertions(+), 34 deletions(-) rename src/main/java/{ATM.java => Menu.java} (84%) rename src/main/java/{LogInScreen.java => UserManagement.java} (85%) delete mode 100644 src/main/test/ATMTest.java create mode 100644 src/main/test/MenuTest.java diff --git a/README.md b/README.md index 92d73b7..7aac238 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# project-2-ATM -Week 2 project: ATM Simulator +# project-2-Menu +Week 2 project: Menu Simulator -## ATM Requirements +## Menu Requirements Every feature must have corresponding unit tests Tests should demonstrate proper behavior, and proper handling of misuse (eg. attempts to deposit/transfer/withdraw negative amounts diff --git a/pom.xml b/pom.xml index c4ae8fd..3187db7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 io.zipcoder - project-2-atm + project-2-menu 1.0-SNAPSHOT diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1d4ec81..2eee3e9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,7 +4,7 @@ public class Main { public static void main(String[] args){ - ATM atm = new ATM(); - atm.printMenus(); + Menu menu = new Menu(); + menu.printMenus(); } } diff --git a/src/main/java/ATM.java b/src/main/java/Menu.java similarity index 84% rename from src/main/java/ATM.java rename to src/main/java/Menu.java index f13628e..93b7cfb 100644 --- a/src/main/java/ATM.java +++ b/src/main/java/Menu.java @@ -1,16 +1,14 @@ -import java.util.Scanner; - -public class ATM { +public class Menu { private Console c; private Integer userInput; - private LogInScreen ls; + private UserManagement ls; private boolean loggedIn; private String currentUser; - public ATM () { + public Menu() { this.c = new Console(); - this.ls = new LogInScreen(); + this.ls = new UserManagement(); this.loggedIn = false; this.currentUser = ""; } @@ -53,16 +51,21 @@ public void printWelcomeMenu() { public void printUserMenu() { System.out.println("WELCOME " + this.currentUser); System.out.println("USER MENU"); - System.out.println("1 - LogOut"); + System.out.println("0 - LogOut"); + System.out.println("1 - Withdraw"); + System.out.println("2 - Transfer Funds"); + System.out.println("3 - Check Balance"); this.userInput = c.getIntegerInput(); switch (userInput) { - case 1: + case 0: this.loggedIn = false; this.currentUser = ""; this.printWelcomeMenu(); break; + case 1: + default: System.out.println("Invalid input. Please select one of the listed options."); break; diff --git a/src/main/java/User.java b/src/main/java/User.java index 779f1dc..5ac0ba5 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -35,7 +35,7 @@ public class User { // default constructor public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? - //Account[] accounts = new Account[30]; // <- length of array? + //Account[] accounts = new Account[3]; // <- length of array? } @@ -47,12 +47,12 @@ public User(String username, String password) { } // Constructor for user with name, password, and account - public User(String username, String password /*Account[] accounts*/) { - this.username = username; - this.password = password; + //public User(String username, String password Account[] accounts) { + //this.username = username; + //this.password = password; //this.accounts = accounts; - } + //} /* // METHODS diff --git a/src/main/java/LogInScreen.java b/src/main/java/UserManagement.java similarity index 85% rename from src/main/java/LogInScreen.java rename to src/main/java/UserManagement.java index 8c22c16..a92af04 100644 --- a/src/main/java/LogInScreen.java +++ b/src/main/java/UserManagement.java @@ -1,16 +1,22 @@ +import java.util.ArrayList; import java.util.HashMap; -public class LogInScreen { +public class UserManagement { Console c = new Console(); private String enteredUserName; private String enteredPassword; private HashMap userNamePasswordMap; + private ArrayList userAccountsList; - public LogInScreen() { - // FOR TESTING + public UserManagement() { this.userNamePasswordMap = new HashMap(); + // FOR TESTING this.userNamePasswordMap.put("TestAccount", "123"); + + this.userAccountsList = new ArrayList(); + // FOR TESTING + userAccountsList.add(new User("TestAccount", "123")); } public String getEnteredUserName() { @@ -61,6 +67,7 @@ public boolean createNewUserAccount() { while (attempts < 3) { if (this.validateUserNameExists() == false) { getPassword(); + setUpUserAccount(); System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!"); return true; } else { @@ -74,7 +81,7 @@ public boolean createNewUserAccount() { public void setUpUserAccount() { this.userNamePasswordMap.put(this.enteredUserName, this.enteredPassword); - User newUser = new User(this.enteredUserName, this.enteredPassword); + this.userAccountsList.add(new User(this.enteredUserName, this.enteredPassword)); } } diff --git a/src/main/test/ATMTest.java b/src/main/test/ATMTest.java deleted file mode 100644 index fd6cd73..0000000 --- a/src/main/test/ATMTest.java +++ /dev/null @@ -1,10 +0,0 @@ -import org.testng.annotations.Test; - -public class ATMTest { - - @Test - public void testGetInitialInput(){ - ATM atmTest = new ATM(); - atmTest.printWelcomeMenu(); - } -} diff --git a/src/main/test/LoginScreenTest.java b/src/main/test/LoginScreenTest.java index 3d3b1fa..3f27a1d 100644 --- a/src/main/test/LoginScreenTest.java +++ b/src/main/test/LoginScreenTest.java @@ -1,7 +1,7 @@ public class LoginScreenTest { public void testLoginScreen() { - LogInScreen ls = new LogInScreen(); + UserManagement ls = new UserManagement(); } diff --git a/src/main/test/MenuTest.java b/src/main/test/MenuTest.java new file mode 100644 index 0000000..ef27336 --- /dev/null +++ b/src/main/test/MenuTest.java @@ -0,0 +1,10 @@ +import org.testng.annotations.Test; + +public class MenuTest { + + @Test + public void testGetInitialInput(){ + Menu menuTest = new Menu(); + menuTest.printWelcomeMenu(); + } +} From 5c4a99bb1484f3a7f01a3b4d4ae11a513abcc75b Mon Sep 17 00:00:00 2001 From: Monali Date: Sun, 14 Mar 2021 10:42:30 -0400 Subject: [PATCH 12/28] adding some more changes --- pom.xml | 12 ++ src/main/java/ATM.java | 38 ++++-- src/main/java/Account.java | 30 +++++ src/main/java/User.java | 230 ++++++++++++++++++------------------- 4 files changed, 186 insertions(+), 124 deletions(-) diff --git a/pom.xml b/pom.xml index 3fe1310..32892ef 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder project-2-atm 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.testng diff --git a/src/main/java/ATM.java b/src/main/java/ATM.java index e42ed4d..cbc3e96 100644 --- a/src/main/java/ATM.java +++ b/src/main/java/ATM.java @@ -12,20 +12,15 @@ public static void main(String[] args) { savings.setType("Savings"); savings.setBalance(0.00); + Account TxnHistory = new Account(); + TxnHistory.setType("Transaction"); NumberFormat formatter = NumberFormat.getCurrencyInstance(); Scanner sc = new Scanner(System.in); boolean session = true; + while (session) { -// Menu options for the user - System.out.print("\nATM Menu: \n \n" - + "1. Deposit Money \n" - + "2. Withdraw Money \n" - + "3. Transfer Funds \n" - + "4. Check Account Balance\n" - + "5. End Session\n \n" - + "Enter selection: "); - Integer selection = sc.nextInt(); + Integer selection = displayMainMenu(); if (selection <1 || selection >5){ System.out.println("Error - Please enter correct option"); @@ -48,6 +43,7 @@ public static void main(String[] args) { }else { savings.deposit(deposit); System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + TxnHistory.printTxn("Savings Deposit ", deposit, savings.getBalance()); } } else if (depAccount == 2) { System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); @@ -59,6 +55,7 @@ public static void main(String[] args) { }else { checking.deposit(deposit); System.out.println("\nChecking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + TxnHistory.printTxn("Checking Deposit", deposit, checking.getBalance()); } } else{ @@ -81,6 +78,7 @@ public static void main(String[] args) { else { savings.withdraw(withdraw); System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + TxnHistory.printTxn("Savings withdraw ", withdraw, savings.getBalance()); } } else if (witAccount == 2) { @@ -94,6 +92,7 @@ else if (witAccount == 2) { else { checking.withdraw(withdraw); System.out.println("\nYour Checking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + TxnHistory.printTxn("Checking withdraw", withdraw, checking.getBalance()); } } break; @@ -149,4 +148,25 @@ else if (tranAccount == 2) { } System.out.println("\nThank you for banking with us! Have a nice time.\n"); } + + public static Integer displayMainMenu() { + Scanner sc1 = new Scanner(System.in); + System.out.print("\nATM Menu: \n \n" + + "1. Deposit Money \n" + + "2. Withdraw Money \n" + + "3. Transfer Funds \n" + + "4. Check Account Balance\n" + + "5. End Session\n \n" + + "Enter selection: "); + Integer selection1 = sc1.nextInt(); + return selection1; + } + } +/// //Time display +// public static void getTime(){ +// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); +// LocalDateTime now = LocalDateTime.now(); +// displayValue = (timeFormat.format(now)); +// } +///add switch case 6 for other options : create new account, close account, print transaction receipt \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 9f3ccde..1106729 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -1,3 +1,6 @@ +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + public class Account { String type; @@ -5,9 +8,11 @@ public class Account { void setType(String accType) { + type = accType; } void setBalance(Double accBal) { + balance = accBal; } @@ -15,9 +20,34 @@ void deposit(Double dep) { balance = balance + dep; } void withdraw(Double wit) { + balance = balance - wit; } Double getBalance() { + return balance; } + void printTxn(String txnType, Double amt, Double balance){ + + System.out.println(""); + System.out.println("|----------------------------------------|"); + System.out.println("| Zip Code Wilmington branch |"); + System.out.println("|----------------------------------------|"); + System.out.println("|" + dateTime() + " "+"|"); + System.out.println("|----------------------------------------|"); + System.out.println("| Transaction Receipt |"); + System.out.println("|" + txnType + " " +"|"); + System.out.println("|" + amt + "" + " "+ "|"); + System.out.println("| Remaining Balance: " + balance + " " + "|"); + System.out.println("|----------------------------------------|"); + + } + String dateTime(){ + + DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + //System.out.println (timeFormat.format(now)); + + return timeFormat.format(now); + } } \ No newline at end of file diff --git a/src/main/java/User.java b/src/main/java/User.java index 41f8926..c6a4043 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,115 +1,115 @@ -/* -Questions: -1. instance field password - access modifier for this private? if private, do we need a getter for this? -2. Constructors - - 2.1 a constructor that sets up a user with just their userName & password.. can make a user and not - necessarily need to assign them an account right away. - 2.2 should default constructor create empty accounts array of specified length? what would be the use - in that? -3. exceptions - how to set up? intelliJ interface different from the images from Dolio -4. JUnit testing - how to configure? -5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? account number as int data type? - -7. Do we need to set up a get password method? -8. Do we need a getter for Accounts[] array of user's accounts? -9. ***** Do we need to use a map for username and passwords? **** -10. Help with syntax for the add/remove functions of user's account array -11. Help with syntax for the get accounts array -12. need console class? manages console interactions. Create a console mock for testing - (provide scripted user input using this object) -13. persistence = the Dikstra 2 stack algorithm - implement? -14. users are authenticated with a password - generated or provided on user creation? - generated password created with default constructor? - - */ - - -public class User { - - public String username; - public String password; // *** access modifier for this??? if private, do we need a getter for this? - public Account[] accounts; - - - // CONSTRUCTORS - - // default constructor - public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? - Account[] accounts = new Account[30]; // <- length of array? - - - } - - // Constructor for user with name & password - public User(String username, String password) { - this.username = username; - this.password = password; - } - - // Constructor for user with name, password, and account - public User(String username, String password, Account[] accounts) { - this.username = username; - this.password = password; - this.accounts = accounts; - - } - - - // METHODS - - // sets userName if none assigned at construction, else resets username - public void setUsername(String username) { - - this.username = username; - } - - // sets password if none assigned at construction, else resets password - public void setPassword(String password) { // *** access modifier for this??? - this.password = password; - - } - - // returns username as string - public String getUsername() { - - return username; - } - - // returns password as string - public String getPassword() { // *** access modifier? - - return password; - } - - // adds new account to end of user's account array - public void addAccount(Account[] accounts, Account accountToAdd) { - int i = 0; - for (Account[] element : accounts) { - if (element[i] == null) { - element[i] += accountToAdd; // **** HELP W THE SYNTAX OF THIS METHOD *** - } i++; - } - } - - // removes specified account from user's account array, replaces space in index with null - public void removeAccount(Account[] accounts, Account accountToRemove) { - int i = 0; - for (Account[] element : accounts) { // for each element in the User's array of their accounts, - // check to see if the value at i is equal to the account to remove - if (element[i] == accountToRemove) { // if the value at accounts[i] is equal to the account to remove, - element[i] = null; // replace the value at accounts[i] with null - } i++; - } - } - - // returns accounts, prints accounts array to string - public Account[] getAccounts() { - System.out.println(accounts.toString); // double check syntax on this one? - return accounts; - } - - -} - - - +///* +//Questions: +//1. instance field password - access modifier for this private? if private, do we need a getter for this? +//2. Constructors - +// 2.1 a constructor that sets up a user with just their userName & password.. can make a user and not +// necessarily need to assign them an account right away. +// 2.2 should default constructor create empty accounts array of specified length? what would be the use +// in that? +//3. exceptions - how to set up? intelliJ interface different from the images from Dolio +//4. JUnit testing - how to configure? +//5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? account number as int data type? +// +//7. Do we need to set up a get password method? +//8. Do we need a getter for Accounts[] array of user's accounts? +//9. ***** Do we need to use a map for username and passwords? **** +//10. Help with syntax for the add/remove functions of user's account array +//11. Help with syntax for the get accounts array +//12. need console class? manages console interactions. Create a console mock for testing +// (provide scripted user input using this object) +//13. persistence = the Dikstra 2 stack algorithm - implement? +//14. users are authenticated with a password - generated or provided on user creation? +// generated password created with default constructor? +// +// */ +// +// +//public class User { +// +// public String username; +// public String password; // *** access modifier for this??? if private, do we need a getter for this? +// public Account[] accounts; +// +// +// // CONSTRUCTORS +// +// // default constructor +// public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? +// Account[] accounts = new Account[30]; // <- length of array? +// +// +// } +// +// // Constructor for user with name & password +// public User(String username, String password) { +// this.username = username; +// this.password = password; +// } +// +// // Constructor for user with name, password, and account +// public User(String username, String password, Account[] accounts) { +// this.username = username; +// this.password = password; +// this.accounts = accounts; +// +// } +// +// +// // METHODS +// +// // sets userName if none assigned at construction, else resets username +// public void setUsername(String username) { +// +// this.username = username; +// } +// +// // sets password if none assigned at construction, else resets password +// public void setPassword(String password) { // *** access modifier for this??? +// this.password = password; +// +// } +// +// // returns username as string +// public String getUsername() { +// +// return username; +// } +// +// // returns password as string +// public String getPassword() { // *** access modifier? +// +// return password; +// } +// +// // adds new account to end of user's account array +// public void addAccount(Account[] accounts, Account accountToAdd) { +// int i = 0; +// for (Account[] element : accounts) { +// if (element[i] == null) { +// element[i] += accountToAdd; // **** HELP W THE SYNTAX OF THIS METHOD *** +// } i++; +// } +// } +// +// // removes specified account from user's account array, replaces space in index with null +// public void removeAccount(Account[] accounts, Account accountToRemove) { +// int i = 0; +// for (Account[] element : accounts) { // for each element in the User's array of their accounts, +// // check to see if the value at i is equal to the account to remove +// if (element[i] == accountToRemove) { // if the value at accounts[i] is equal to the account to remove, +// element[i] = null; // replace the value at accounts[i] with null +// } i++; +// } +// } +// +// // returns accounts, prints accounts array to string +// public Account[] getAccounts() { +// System.out.println(accounts.toString); // double check syntax on this one? +// return accounts; +// } +// +// +//} +// +// +// From 84f3bb9097e1d9d10123192a2017470f79797443 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 12:03:37 -0400 Subject: [PATCH 13/28] Worked on merging together our code --- README.md | 2 +- src/main/java/ATM.java | 172 ----------------------------- src/main/java/Account.java | 163 ++++++++++++++++++++------- src/main/java/Menu.java | 29 ++++- src/main/java/TranscationHist.java | 53 +++++++++ src/main/java/UserManagement.java | 2 + 6 files changed, 205 insertions(+), 216 deletions(-) delete mode 100644 src/main/java/ATM.java create mode 100644 src/main/java/TranscationHist.java diff --git a/README.md b/README.md index 7aac238..5679ccc 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Tests should demonstrate proper behavior, and proper handling of misuse (eg. att - Checking - Savings - Investment -- Account Actions +- TranscationHist Actions - Withdraw from acct - Deposit to acct - Transfer across accounts (self) diff --git a/src/main/java/ATM.java b/src/main/java/ATM.java deleted file mode 100644 index cbc3e96..0000000 --- a/src/main/java/ATM.java +++ /dev/null @@ -1,172 +0,0 @@ -import java.text.NumberFormat; -import java.util.Scanner; -public class ATM { - public static void main(String[] args) { -// Create and instantiate checking Account objects - Account checking = new Account(); - checking.setType("Checking"); - checking.setBalance(0.00); - -// Create and instantiate checking Account objects - Account savings = new Account(); - savings.setType("Savings"); - savings.setBalance(0.00); - - Account TxnHistory = new Account(); - TxnHistory.setType("Transaction"); - - NumberFormat formatter = NumberFormat.getCurrencyInstance(); - Scanner sc = new Scanner(System.in); - boolean session = true; - - while (session) { - Integer selection = displayMainMenu(); - - if (selection <1 || selection >5){ - System.out.println("Error - Please enter correct option"); - } - - switch (selection) { -// case 1 handles the depositing of money - case 1: - System.out.print("Enter (1) for Savings or (2) for Checking: "); - Integer depAccount = sc.nextInt(); - -// Keeps track of which account to deposit money to - checking or saving - if (depAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.println("How much money would you like to deposit?"); - - Double deposit = sc.nextDouble(); - if (deposit < 0){ - System.out.println("Please enter amount greater than ZERO"); - }else { - savings.deposit(deposit); - System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); - TxnHistory.printTxn("Savings Deposit ", deposit, savings.getBalance()); - } - } else if (depAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.println("How much money would you like to deposit?"); - - Double deposit = sc.nextDouble(); - if (deposit < 0){ - System.out.println("Please enter amount greater than ZERO"); - }else { - checking.deposit(deposit); - System.out.println("\nChecking balance is now: " + formatter.format(checking.getBalance()) + "\n"); - TxnHistory.printTxn("Checking Deposit", deposit, checking.getBalance()); - } - } - else{ - System.out.println("Please enter valid input (1 for Savings and 2 for Checking)"); - } - - break; -// case 2 handles the withdrawal of money - case 2: - System.out.print("\nEnter (1) for Savings or (2) for Checking: "); - Integer witAccount = sc.nextInt(); // Keeps track of which account to withdraw from - if (witAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.println("How much money would you like to withdraw?"); - - Double withdraw = sc.nextDouble(); - if (withdraw > savings.balance){ - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); - } - else { - savings.withdraw(withdraw); - System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); - TxnHistory.printTxn("Savings withdraw ", withdraw, savings.getBalance()); - } - } - else if (witAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.println("How much money would you like to withdraw?"); - - Double withdraw = sc.nextDouble(); - if(withdraw > checking.balance){ - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); - } - else { - checking.withdraw(withdraw); - System.out.println("\nYour Checking balance is now: " + formatter.format(checking.getBalance()) + "\n"); - TxnHistory.printTxn("Checking withdraw", withdraw, checking.getBalance()); - } - } - break; -// case 3 handles the transfer of funds - case 3: - System.out.print("\nFrom which account do you wish to transfer funds from?, (1) for Savings or (2) for Checking: "); - Integer tranAccount = sc.nextInt(); - if (tranAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.print("How much money do you wish to transfer from Savings to Checking?: "); - - Double tranAmount = sc.nextDouble(); - if (tranAmount > savings.balance){ - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); - } - else { - savings.withdraw(tranAmount); - checking.deposit(tranAmount); - - System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - } - } - else if (tranAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.print("How much money do you wish to transfer from Checking to Saving?: "); - - Double tranAmount = sc.nextDouble(); - if(tranAmount > checking.balance){ - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); - } - else { - checking.withdraw(tranAmount); - savings.deposit(tranAmount); - - System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Checking to Savings"); - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - } - } - break; -// case 4 simply outputs the balances of both Checking and Savings accounts - case 4: - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - break; -// case 5 breaks out of the (while) loop when the user is finished using the ATM - case 5: - session = false; - break; - } - } - System.out.println("\nThank you for banking with us! Have a nice time.\n"); - } - - public static Integer displayMainMenu() { - Scanner sc1 = new Scanner(System.in); - System.out.print("\nATM Menu: \n \n" - + "1. Deposit Money \n" - + "2. Withdraw Money \n" - + "3. Transfer Funds \n" - + "4. Check Account Balance\n" - + "5. End Session\n \n" - + "Enter selection: "); - Integer selection1 = sc1.nextInt(); - return selection1; - } - -} -/// //Time display -// public static void getTime(){ -// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); -// LocalDateTime now = LocalDateTime.now(); -// displayValue = (timeFormat.format(now)); -// } -///add switch case 6 for other options : create new account, close account, print transaction receipt \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 1106729..500f545 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -1,53 +1,142 @@ -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - +import java.text.NumberFormat; +import java.util.Scanner; public class Account { - String type; - double balance; - + public Account() { + checking.setType("Checking"); + checking.setBalance(0.00); - void setType(String accType) { + savings.setType("Savings"); + savings.setBalance(0.00); - type = accType; + TxnHistory.setType("Transaction"); } - void setBalance(Double accBal) { - balance = accBal; - } + // Create and instantiate checking Account objects + TranscationHist checking = new TranscationHist(); + // Create and instantiate checking Account objects + TranscationHist savings = new TranscationHist(); + TranscationHist TxnHistory = new TranscationHist(); + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + private Console c; + Scanner sc = new Scanner(System.in); + boolean session = true; + + + public void depositMoney() { + System.out.print("Enter (1) for Savings or (2) for Checking: "); + Integer depAccount = sc.nextInt(); + +// Keeps track of which account to deposit money to - checking or saving + if (depAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.println("How much money would you like to deposit?"); + + Double deposit = sc.nextDouble(); + if (deposit < 0) { + System.out.println("Please enter amount greater than ZERO"); + } else { + savings.deposit(deposit); + System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + TxnHistory.printTxn("Savings Deposit ", deposit, savings.getBalance()); + } + } else if (depAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.println("How much money would you like to deposit?"); + + Double deposit = sc.nextDouble(); + if (deposit < 0) { + System.out.println("Please enter amount greater than ZERO"); + } else { + checking.deposit(deposit); + System.out.println("\nChecking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + TxnHistory.printTxn("Checking Deposit", deposit, checking.getBalance()); + } + } else { + System.out.println("Please enter valid input (1 for Savings and 2 for Checking)"); + } - void deposit(Double dep) { - balance = balance + dep; } - void withdraw(Double wit) { - balance = balance - wit; + public void withdrawMoney() { + System.out.print("\nEnter (1) for Savings or (2) for Checking: "); + Integer witAccount = sc.nextInt(); // Keeps track of which account to withdraw from + if (witAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.println("How much money would you like to withdraw?"); + + Double withdraw = sc.nextDouble(); + if (withdraw > savings.balance) { + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); + } else { + savings.withdraw(withdraw); + System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); + TxnHistory.printTxn("Savings withdraw ", withdraw, savings.getBalance()); + } + } else if (witAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.println("How much money would you like to withdraw?"); + + Double withdraw = sc.nextDouble(); + if (withdraw > checking.balance) { + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); + } else { + checking.withdraw(withdraw); + System.out.println("\nYour Checking balance is now: " + formatter.format(checking.getBalance()) + "\n"); + TxnHistory.printTxn("Checking withdraw", withdraw, checking.getBalance()); + } + } + } - Double getBalance() { - return balance; + public void transferMoney() { + System.out.print("\nFrom which account do you wish to transfer funds from?, (1) for Savings or (2) for Checking: "); + Integer tranAccount = sc.nextInt(); + if (tranAccount == 1) { + System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from Savings to Checking?: "); + + Double tranAmount = sc.nextDouble(); + if (tranAmount > savings.balance) { + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + } else { + savings.withdraw(tranAmount); + checking.deposit(tranAmount); + + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); + } + } else if (tranAccount == 2) { + System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from Checking to Saving?: "); + + Double tranAmount = sc.nextDouble(); + if (tranAmount > checking.balance) { + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + } else { + checking.withdraw(tranAmount); + savings.deposit(tranAmount); + + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Checking to Savings"); + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); + } + } + } - void printTxn(String txnType, Double amt, Double balance){ - - System.out.println(""); - System.out.println("|----------------------------------------|"); - System.out.println("| Zip Code Wilmington branch |"); - System.out.println("|----------------------------------------|"); - System.out.println("|" + dateTime() + " "+"|"); - System.out.println("|----------------------------------------|"); - System.out.println("| Transaction Receipt |"); - System.out.println("|" + txnType + " " +"|"); - System.out.println("|" + amt + "" + " "+ "|"); - System.out.println("| Remaining Balance: " + balance + " " + "|"); - System.out.println("|----------------------------------------|"); + public void checkBalance() { + System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); + System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); } - String dateTime(){ +} - DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); - LocalDateTime now = LocalDateTime.now(); - //System.out.println (timeFormat.format(now)); - return timeFormat.format(now); - } -} \ No newline at end of file +/// //Time display +// public static void getTime(){ +// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); +// LocalDateTime now = LocalDateTime.now(); +// displayValue = (timeFormat.format(now)); +// } +///add switch case 6 for other options : create new account, close account, print transaction receipt \ No newline at end of file diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index 93b7cfb..71475c6 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Menu { private Console c; @@ -5,17 +7,19 @@ public class Menu { private UserManagement ls; private boolean loggedIn; private String currentUser; + private Account userAccount; public Menu() { this.c = new Console(); this.ls = new UserManagement(); this.loggedIn = false; this.currentUser = ""; + this.userAccount = new Account(); } public void printMenus() { - while(true) { + while (true) { if (this.loggedIn == false) { this.printWelcomeMenu(); @@ -43,6 +47,8 @@ public void printWelcomeMenu() { this.loggedIn = ls.createNewUserAccount(); this.currentUser = ls.getEnteredUserName(); break; + case 3: + default: System.out.println("Invalid input. Please select either 1 or 2."); } @@ -52,9 +58,10 @@ public void printUserMenu() { System.out.println("WELCOME " + this.currentUser); System.out.println("USER MENU"); System.out.println("0 - LogOut"); - System.out.println("1 - Withdraw"); - System.out.println("2 - Transfer Funds"); - System.out.println("3 - Check Balance"); + System.out.println("1 - Deposit"); + System.out.println("2 - Withdraw"); + System.out.println("3 - Transfer Funds"); + System.out.println("4 - Check Balance"); this.userInput = c.getIntegerInput(); @@ -65,12 +72,22 @@ public void printUserMenu() { this.printWelcomeMenu(); break; case 1: - + this.userAccount.depositMoney(); + break; + case 2: + this.userAccount.withdrawMoney(); + break; + case 3: + this.userAccount.transferMoney(); + break; + case 4: + this.userAccount.checkBalance(); + break; default: System.out.println("Invalid input. Please select one of the listed options."); break; - } } + } } diff --git a/src/main/java/TranscationHist.java b/src/main/java/TranscationHist.java new file mode 100644 index 0000000..d16d41b --- /dev/null +++ b/src/main/java/TranscationHist.java @@ -0,0 +1,53 @@ +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class TranscationHist { + + String type; + double balance; + + + void setType(String accType) { + + type = accType; + } + void setBalance(Double accBal) { + + balance = accBal; + } + + void deposit(Double dep) { + balance = balance + dep; + } + void withdraw(Double wit) { + + balance = balance - wit; + } + Double getBalance() { + + return balance; + } + void printTxn(String txnType, Double amt, Double balance){ + + System.out.println(""); + System.out.println("|----------------------------------------|"); + System.out.println("| BANK OF ZIP CODE WILMINGTON DE |"); + System.out.println("|----------------------------------------|"); + System.out.println("|" + dateTime() + " "+"|"); + System.out.println("|----------------------------------------|"); + System.out.println("| Transaction Receipt |"); + System.out.println("|" + txnType + " " +"|"); + System.out.println("|" + amt + "" + " "+ "|"); + System.out.println("| Remaining Balance: " + balance + " " + "|"); + System.out.println("|----------------------------------------|"); + + } + String dateTime(){ + + DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + //System.out.println (timeFormat.format(now)); + + return timeFormat.format(now); + } +} \ No newline at end of file diff --git a/src/main/java/UserManagement.java b/src/main/java/UserManagement.java index a92af04..20e97bb 100644 --- a/src/main/java/UserManagement.java +++ b/src/main/java/UserManagement.java @@ -13,10 +13,12 @@ public UserManagement() { this.userNamePasswordMap = new HashMap(); // FOR TESTING this.userNamePasswordMap.put("TestAccount", "123"); + this.userNamePasswordMap.put("TestAccount2", "456"); this.userAccountsList = new ArrayList(); // FOR TESTING userAccountsList.add(new User("TestAccount", "123")); + userAccountsList.add(new User("TestAccount2", "456")); } public String getEnteredUserName() { From 727741c5f4c0d59f95b960b2fd049ef159bd8826 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 16:47:40 -0400 Subject: [PATCH 14/28] Added ability to close account & switch between accounts w/o losing data, & select Bank account in menu options --- README.md | 4 +- src/main/java/Account.java | 142 ------------------ src/main/java/AccountEngine.java | 82 ++++++++++ ...{TranscationHist.java => BankAccount.java} | 30 ++-- src/main/java/Menu.java | 112 ++++++++++---- src/main/java/User.java | 112 -------------- src/main/java/UserAccount.java | 48 ++++++ ...UserManagement.java => WelcomeEngine.java} | 50 +++--- src/main/test/LoginScreenTest.java | 2 +- 9 files changed, 255 insertions(+), 327 deletions(-) delete mode 100644 src/main/java/Account.java create mode 100644 src/main/java/AccountEngine.java rename src/main/java/{TranscationHist.java => BankAccount.java} (72%) delete mode 100644 src/main/java/User.java create mode 100644 src/main/java/UserAccount.java rename src/main/java/{UserManagement.java => WelcomeEngine.java} (58%) diff --git a/README.md b/README.md index 5679ccc..2414814 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Week 2 project: Menu Simulator Every feature must have corresponding unit tests Tests should demonstrate proper behavior, and proper handling of misuse (eg. attempts to deposit/transfer/withdraw negative amounts -- User interface: CLI (Command line interface) Only +- UserAccount interface: CLI (Command line interface) Only - Direct Input - Numbered options (instead of on-screen buttons) - ASCII art welcome but not required @@ -14,7 +14,7 @@ Tests should demonstrate proper behavior, and proper handling of misuse (eg. att - Checking - Savings - Investment -- TranscationHist Actions +- BankAccount Actions - Withdraw from acct - Deposit to acct - Transfer across accounts (self) diff --git a/src/main/java/Account.java b/src/main/java/Account.java deleted file mode 100644 index 500f545..0000000 --- a/src/main/java/Account.java +++ /dev/null @@ -1,142 +0,0 @@ -import java.text.NumberFormat; -import java.util.Scanner; -public class Account { - - public Account() { - checking.setType("Checking"); - checking.setBalance(0.00); - - savings.setType("Savings"); - savings.setBalance(0.00); - - TxnHistory.setType("Transaction"); - } - - // Create and instantiate checking Account objects - TranscationHist checking = new TranscationHist(); - // Create and instantiate checking Account objects - TranscationHist savings = new TranscationHist(); - TranscationHist TxnHistory = new TranscationHist(); - NumberFormat formatter = NumberFormat.getCurrencyInstance(); - private Console c; - Scanner sc = new Scanner(System.in); - boolean session = true; - - - public void depositMoney() { - System.out.print("Enter (1) for Savings or (2) for Checking: "); - Integer depAccount = sc.nextInt(); - -// Keeps track of which account to deposit money to - checking or saving - if (depAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.println("How much money would you like to deposit?"); - - Double deposit = sc.nextDouble(); - if (deposit < 0) { - System.out.println("Please enter amount greater than ZERO"); - } else { - savings.deposit(deposit); - System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); - TxnHistory.printTxn("Savings Deposit ", deposit, savings.getBalance()); - } - } else if (depAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.println("How much money would you like to deposit?"); - - Double deposit = sc.nextDouble(); - if (deposit < 0) { - System.out.println("Please enter amount greater than ZERO"); - } else { - checking.deposit(deposit); - System.out.println("\nChecking balance is now: " + formatter.format(checking.getBalance()) + "\n"); - TxnHistory.printTxn("Checking Deposit", deposit, checking.getBalance()); - } - } else { - System.out.println("Please enter valid input (1 for Savings and 2 for Checking)"); - } - - } - - public void withdrawMoney() { - System.out.print("\nEnter (1) for Savings or (2) for Checking: "); - Integer witAccount = sc.nextInt(); // Keeps track of which account to withdraw from - if (witAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.println("How much money would you like to withdraw?"); - - Double withdraw = sc.nextDouble(); - if (withdraw > savings.balance) { - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); - } else { - savings.withdraw(withdraw); - System.out.println("\nYour Savings balance is now: " + formatter.format(savings.getBalance()) + "\n"); - TxnHistory.printTxn("Savings withdraw ", withdraw, savings.getBalance()); - } - } else if (witAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.println("How much money would you like to withdraw?"); - - Double withdraw = sc.nextDouble(); - if (withdraw > checking.balance) { - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount"); - } else { - checking.withdraw(withdraw); - System.out.println("\nYour Checking balance is now: " + formatter.format(checking.getBalance()) + "\n"); - TxnHistory.printTxn("Checking withdraw", withdraw, checking.getBalance()); - } - } - - } - - public void transferMoney() { - System.out.print("\nFrom which account do you wish to transfer funds from?, (1) for Savings or (2) for Checking: "); - Integer tranAccount = sc.nextInt(); - if (tranAccount == 1) { - System.out.println("\nYour current Savings balance is: " + formatter.format(savings.getBalance()) + "\n"); - System.out.print("How much money do you wish to transfer from Savings to Checking?: "); - - Double tranAmount = sc.nextDouble(); - if (tranAmount > savings.balance) { - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); - } else { - savings.withdraw(tranAmount); - checking.deposit(tranAmount); - - System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - } - } else if (tranAccount == 2) { - System.out.println("\nYour current Checking balance is: " + formatter.format(checking.getBalance()) + "\n"); - System.out.print("How much money do you wish to transfer from Checking to Saving?: "); - - Double tranAmount = sc.nextDouble(); - if (tranAmount > checking.balance) { - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); - } else { - checking.withdraw(tranAmount); - savings.deposit(tranAmount); - - System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Checking to Savings"); - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - } - } - - } - - public void checkBalance() { - System.out.println("\nChecking Balance: " + formatter.format(checking.getBalance())); - System.out.println("Savings Balance: " + formatter.format(savings.getBalance()) + "\n"); - } -} - - -/// //Time display -// public static void getTime(){ -// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); -// LocalDateTime now = LocalDateTime.now(); -// displayValue = (timeFormat.format(now)); -// } -///add switch case 6 for other options : create new account, close account, print transaction receipt \ No newline at end of file diff --git a/src/main/java/AccountEngine.java b/src/main/java/AccountEngine.java new file mode 100644 index 0000000..2571111 --- /dev/null +++ b/src/main/java/AccountEngine.java @@ -0,0 +1,82 @@ + +import java.text.NumberFormat; +import java.util.Scanner; +public class AccountEngine { + + private NumberFormat formatter; + private Console c; + + public AccountEngine() { + this.c = new Console(); + this.formatter = NumberFormat.getCurrencyInstance(); + } + + public void depositMoney(BankAccount chosenBankAccount) { + // Keeps track of which account to deposit money to - checking or saving + System.out.println("\nYour current Savings balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + System.out.println("How much money would you like to deposit?"); + + Double deposit; + deposit = c.getDoubleInput(); + if (deposit < 0) { + System.out.println("Please enter amount greater than ZERO"); + } else { + chosenBankAccount.deposit(deposit); + System.out.println("\nYour Savings balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + chosenBankAccount.printTxn("Savings Deposit ", deposit, chosenBankAccount.getBalance()); + System.out.println(); + } + } + + public void withdrawMoney(BankAccount chosenBankAccount) { + + System.out.println("\nYour current Savings balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + System.out.println("How much money would you like to withdraw?"); + + Double withdraw; + withdraw = c.getDoubleInput(); + if (withdraw > chosenBankAccount.getBalance()) { + System.out.println("INSUFFICIENT BALANCE! Your request will not be processed. \n"); + } else { + chosenBankAccount.withdraw(withdraw); + System.out.println("\nYour Savings balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + chosenBankAccount.printTxn("Savings withdraw ", withdraw, chosenBankAccount.getBalance() ); + System.out.println(); + } + } + + public void transferMoney(BankAccount chosenTransferFromAccount, BankAccount chosenTransferToAccount) { + System.out.println("\nYour current Savings balance is: " + formatter.format(chosenTransferFromAccount.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from Savings to Checking?: "); + + Double tranAmount; + tranAmount = c.getDoubleInput(); + if (tranAmount > chosenTransferFromAccount.getBalance()) { + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + } else { + chosenTransferFromAccount.withdraw(tranAmount); + chosenTransferToAccount.deposit(tranAmount); + + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); + System.out.println("\nChecking Balance: " + formatter.format(chosenTransferFromAccount.getBalance())); + System.out.println("Savings Balance: " + formatter.format(chosenTransferToAccount.getBalance()) + "\n"); + } + } + + public void checkBalance (UserAccount currentUser) { + System.out.println("\nChecking Balance: " + formatter.format(currentUser.getCheckingAccount().getBalance())); + System.out.println("Savings Balance: " + formatter.format(currentUser.getSavingsAccount().getBalance())); + System.out.println("Investment Balance: " + formatter.format(currentUser.getInvestmentAccount().getBalance()) + "\n"); + } + + +} + +/// //Time display +// public static void getTime(){ +// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); +// LocalDateTime now = LocalDateTime.now(); +// displayValue = (timeFormat.format(now)); +// } +///add switch case 6 for other options : create new account, close account, print transaction receipt + diff --git a/src/main/java/TranscationHist.java b/src/main/java/BankAccount.java similarity index 72% rename from src/main/java/TranscationHist.java rename to src/main/java/BankAccount.java index d16d41b..687803f 100644 --- a/src/main/java/TranscationHist.java +++ b/src/main/java/BankAccount.java @@ -1,32 +1,38 @@ +import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Map; -public class TranscationHist { +public class BankAccount { - String type; - double balance; + private String accountType; + private double currentBalance; + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + public BankAccount(String chosenAccountType) { + this.accountType = chosenAccountType; + this.currentBalance = 0; + } void setType(String accType) { - - type = accType; + accountType = accType; } void setBalance(Double accBal) { - - balance = accBal; + currentBalance = accBal; } void deposit(Double dep) { - balance = balance + dep; + currentBalance = currentBalance + dep; } - void withdraw(Double wit) { - balance = balance - wit; + void withdraw(Double wit) { + currentBalance = currentBalance - wit; } - Double getBalance() { - return balance; + Double getBalance() { + return currentBalance; } + void printTxn(String txnType, Double amt, Double balance){ System.out.println(""); diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index 71475c6..2e4d9ad 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -1,29 +1,26 @@ -import java.util.Scanner; - public class Menu { - private Console c; - private Integer userInput; - private UserManagement ls; + private UserAccount currentUser; private boolean loggedIn; - private String currentUser; - private Account userAccount; + private Console c; + private WelcomeEngine ls; + private AccountEngine ae; public Menu() { this.c = new Console(); - this.ls = new UserManagement(); + this.ls = new WelcomeEngine(); + this.ae = new AccountEngine(); this.loggedIn = false; - this.currentUser = ""; - this.userAccount = new Account(); + this.currentUser = null; } public void printMenus() { - while (true) { + while (true) { // If user not logged in, show welcome menu if (this.loggedIn == false) { this.printWelcomeMenu(); - } else { + } else { // If user is logged in, show User menu this.printUserMenu(); } } @@ -36,58 +33,107 @@ public void printWelcomeMenu() { System.out.println("PRESS 1 TO LOGIN"); System.out.println("PRESS 2 IF YOU ARE A NEW USER"); - this.userInput = c.getIntegerInput(); + Integer userInput; + userInput = c.getIntegerInput(); switch (userInput) { - case 1: - this.loggedIn = ls.validateLoginCredentials(); - this.currentUser = ls.getEnteredUserName(); - break; - case 2: - this.loggedIn = ls.createNewUserAccount(); - this.currentUser = ls.getEnteredUserName(); + case 1: // LOGIN + this.currentUser = ls.validateLoginCredentials(); + if (this.currentUser != null) { + this.loggedIn = true; + } break; - case 3: - + case 2: // CREATE NEW ACCOUNT + this.currentUser = ls.createNewUserAccount(); + if (this.currentUser != null) { + this.loggedIn = true; + } default: System.out.println("Invalid input. Please select either 1 or 2."); } } public void printUserMenu() { - System.out.println("WELCOME " + this.currentUser); + System.out.println("WELCOME " + this.currentUser.getUsername()); System.out.println("USER MENU"); System.out.println("0 - LogOut"); System.out.println("1 - Deposit"); System.out.println("2 - Withdraw"); System.out.println("3 - Transfer Funds"); System.out.println("4 - Check Balance"); + System.out.println("5 - Close Account"); - this.userInput = c.getIntegerInput(); + Integer userInput; + userInput = c.getIntegerInput(); switch (userInput) { case 0: this.loggedIn = false; - this.currentUser = ""; + this.currentUser = null; this.printWelcomeMenu(); break; - case 1: - this.userAccount.depositMoney(); + case 1: // Deposit + this.ae.depositMoney(this.chooseAccount()); break; - case 2: - this.userAccount.withdrawMoney(); + case 2: // Withdraw + this.ae.withdrawMoney(this.chooseAccount()); break; - case 3: - this.userAccount.transferMoney(); + case 3: // Transfer between accounts + System.out.println("TRANSFER FROM ACCOUNT:"); + BankAccount transferFrom = chooseAccount(); + System.out.println("TRANSFER TO ACCOUNT:"); + BankAccount transferTo = chooseAccount(); + this.ae.transferMoney(transferFrom, transferTo); break; - case 4: - this.userAccount.checkBalance(); + case 4: // Check Balance + this.ae.checkBalance(this.currentUser); + break; + case 5: // Close Account + this.ls.closeAccount(); + this.loggedIn = false; + this.currentUser = null; + this.printWelcomeMenu(); break; default: System.out.println("Invalid input. Please select one of the listed options."); break; } } + + public BankAccount chooseAccount() { + BankAccount currentAccount = null; + System.out.println("Which Account would you like to use?"); + System.out.println("Press 0 to Log Out"); + System.out.println("Press 1 for Checking"); + System.out.println("Press 2 for Savings"); + System.out.println("Press 3 for Investment"); + + Integer userInput = c.getIntegerInput(); + + switch (userInput) { + case 0: // Log out + this.loggedIn = false; + this.currentUser = null; + this.printWelcomeMenu(); + break; + case 1: // Choose checking + currentAccount = this.currentUser.getCheckingAccount(); + break; + case 2: // Choose savings + currentAccount = this.currentUser.getSavingsAccount(); + break; + case 3: // Choose Investments + currentAccount= this.currentUser.getInvestmentAccount(); + break; + default: + System.out.println("Invalid input."); + this.printUserMenu(); + break; + } + + return currentAccount; + } + } diff --git a/src/main/java/User.java b/src/main/java/User.java deleted file mode 100644 index 8699ac1..0000000 --- a/src/main/java/User.java +++ /dev/null @@ -1,112 +0,0 @@ -/* -Questions: -1. instance field password - access modifier for this private? if private, do we need a getter for this? -2. Constructors - - 2.1 a constructor that sets up a user with just their userName & password.. can make a user and not - necessarily need to assign them an account right away. - 2.2 should default constructor create empty accounts array of specified length? what would be the use - in that? -3. exceptions - how to set up? intelliJ interface different from the images from Dolio -4. JUnit testing - how to configure? -5. Do we need to set up an account number that has a limit on length? uniformity with account number properties? account number as int data type? - -7. Do we need to set up a get password method? -8. Do we need a getter for Accounts[] array of user's accounts? -9. ***** Do we need to use a map for username and passwords? **** -10. Help with syntax for the add/remove functions of user's account array -11. Help with syntax for the get accounts array -12. need console class? manages console interactions. Create a console mock for testing - (provide scripted user input using this object) -13. persistence = the Dikstra 2 stack algorithm - implement? -14. users are authenticated with a password - generated or provided on user creation? - generated password created with default constructor? - - */ - - -public class User { - - private String username; - private String password; // *** access modifier for this??? if private, do we need a getter for this? - //public Account[] accounts; - - - // CONSTRUCTORS - - // default constructor - public User() { // <- should this constructor set up an Accounts[] array to an empty array of n length? - //Account[] accounts = new Account[3]; // <- length of array? - - - } - - // Constructor for user with name & password - public User(String username, String password) { - this.username = username; - this.password = password; - } - - // Constructor for user with name, password, and account - //public User(String username, String password Account[] accounts) { - //this.username = username; - //this.password = password; - //this.accounts = accounts; - - //} - -/* - // METHODS - - // sets userName if none assigned at construction, else resets username - public void setUsername(String username) { - - this.username = username; - } - - // sets password if none assigned at construction, else resets password - public void setPassword(String password) { // *** access modifier for this??? - this.password = password; - - } - - // returns username as string - public String getUsername() { - - return username; - } - - // returns password as string - public String getPassword() { // *** access modifier? - - return password; - } - - // adds new account to end of user's account array - public void addAccount(Account[] accounts, Account accountToAdd) { - int i = 0; - for (Account[] element : accounts) { - if (element[i] == null) { - element[i] += accountToAdd; // **** HELP W THE SYNTAX OF THIS METHOD *** - } i++; - } - } - - // removes specified account from user's account array, replaces space in index with null - public void removeAccount(Account[] accounts, Account accountToRemove) { - int i = 0; - for (Account[] element : accounts) { // for each element in the User's array of their accounts, - // check to see if the value at i is equal to the account to remove - if (element[i] == accountToRemove) { // if the value at accounts[i] is equal to the account to remove, - element[i] = null; // replace the value at accounts[i] with null - } i++; - } - } - - // returns accounts, prints accounts array to string - public Account[] getAccounts() { - System.out.println(accounts.toString); // double check syntax on this one? - return accounts; - } - -*/ -} diff --git a/src/main/java/UserAccount.java b/src/main/java/UserAccount.java new file mode 100644 index 0000000..a2462a2 --- /dev/null +++ b/src/main/java/UserAccount.java @@ -0,0 +1,48 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class UserAccount { + + private String username; + private String password; + private Map userBankAccounts; + + public UserAccount(String username, String password) { + this.username = username; + this.password = password; + this.userBankAccounts = new HashMap(); + this.userBankAccounts.put("Checking", new BankAccount("Checking")); + this.userBankAccounts.put("Savings", new BankAccount("Savings")); + this.userBankAccounts.put("Investment", new BankAccount("Investment")); + } + + public void closeCheckingAccount() { + this.userBankAccounts.put("Checking", null); + } + + public void closeSavingsAccount() { + this.userBankAccounts.put("Savings", null); + } + + public void closeInvestmentAccount() { + this.userBankAccounts.put("Investment", null); + } + + public BankAccount getCheckingAccount() { + return this.userBankAccounts.get("Checking"); + } + + public BankAccount getSavingsAccount() { + return this.userBankAccounts.get("Savings"); + } + + public BankAccount getInvestmentAccount() { + return this.userBankAccounts.get("Investment"); + } + + public String getUsername() { + return this.username; + } + +} diff --git a/src/main/java/UserManagement.java b/src/main/java/WelcomeEngine.java similarity index 58% rename from src/main/java/UserManagement.java rename to src/main/java/WelcomeEngine.java index 20e97bb..3a9379a 100644 --- a/src/main/java/UserManagement.java +++ b/src/main/java/WelcomeEngine.java @@ -1,24 +1,24 @@ import java.util.ArrayList; import java.util.HashMap; -public class UserManagement { +public class WelcomeEngine { Console c = new Console(); private String enteredUserName; private String enteredPassword; private HashMap userNamePasswordMap; - private ArrayList userAccountsList; + private HashMap userAccountsList; - public UserManagement() { + public WelcomeEngine() { this.userNamePasswordMap = new HashMap(); // FOR TESTING this.userNamePasswordMap.put("TestAccount", "123"); this.userNamePasswordMap.put("TestAccount2", "456"); - this.userAccountsList = new ArrayList(); + this.userAccountsList = new HashMap(); // FOR TESTING - userAccountsList.add(new User("TestAccount", "123")); - userAccountsList.add(new User("TestAccount2", "456")); + userAccountsList.put("TestAccount", new UserAccount("TestAccount", "123")); + userAccountsList.put("TestAccount2", new UserAccount("TestAccount2", "456")); } public String getEnteredUserName() { @@ -45,25 +45,20 @@ public boolean validatePasswordCorrect() { return this.userNamePasswordMap.get(this.enteredUserName).equals(this.enteredPassword); } - public boolean validateLoginCredentials() { - int attempts = 0; - while (attempts < 3) { - if(this.validateUserNameExists() == false) { - System.out.println("No such user exists."); - attempts += 1; - } else if (this.validatePasswordCorrect() == false) { - System.out.println("Password is incorrect."); - attempts += 1; - } else { - System.out.println("You are now logged in."); - return true; - } + public UserAccount validateLoginCredentials() { + if(this.validateUserNameExists() == false) { + System.out.println("No such user exists."); + } else if (this.validatePasswordCorrect() == false) { + System.out.println("Password is incorrect."); + } else { + System.out.println("You are now logged in."); + return userAccountsList.get(this.enteredUserName); } - return false; + return null; } - public boolean createNewUserAccount() { + public UserAccount createNewUserAccount() { System.out.println("Enter your new username and password."); int attempts = 0; while (attempts < 3) { @@ -71,19 +66,24 @@ public boolean createNewUserAccount() { getPassword(); setUpUserAccount(); System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!"); - return true; + return userAccountsList.get(this.enteredUserName); } else { System.out.println("Username is already taken. Please select another."); attempts += 1; } } - - return false; + return null; } public void setUpUserAccount() { this.userNamePasswordMap.put(this.enteredUserName, this.enteredPassword); - this.userAccountsList.add(new User(this.enteredUserName, this.enteredPassword)); + this.userAccountsList.put(this.enteredUserName, new UserAccount(this.enteredUserName, this.enteredPassword)); + } + + public void closeAccount() { + this.userNamePasswordMap.remove(this.enteredUserName); + this.userAccountsList.remove(this.enteredUserName); + System.out.println("Sorry to see you go" + this.enteredUserName + "! Your account is now closed."); } } diff --git a/src/main/test/LoginScreenTest.java b/src/main/test/LoginScreenTest.java index 3f27a1d..abbaedd 100644 --- a/src/main/test/LoginScreenTest.java +++ b/src/main/test/LoginScreenTest.java @@ -1,7 +1,7 @@ public class LoginScreenTest { public void testLoginScreen() { - UserManagement ls = new UserManagement(); + WelcomeEngine ls = new WelcomeEngine(); } From e2f6b38c0bec49e2dad8ed14cf1ccc1d65dba72d Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 16:59:06 -0400 Subject: [PATCH 15/28] Some small changes --- src/main/java/{AccountEngine.java => AccountTrans.java} | 6 +++--- src/main/java/Menu.java | 8 ++++---- src/main/java/UserAccount.java | 1 - src/main/java/{WelcomeEngine.java => UserManagement.java} | 5 ++--- src/main/test/LoginScreenTest.java | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) rename src/main/java/{AccountEngine.java => AccountTrans.java} (97%) rename src/main/java/{WelcomeEngine.java => UserManagement.java} (97%) diff --git a/src/main/java/AccountEngine.java b/src/main/java/AccountTrans.java similarity index 97% rename from src/main/java/AccountEngine.java rename to src/main/java/AccountTrans.java index 2571111..b2d52d0 100644 --- a/src/main/java/AccountEngine.java +++ b/src/main/java/AccountTrans.java @@ -1,12 +1,12 @@ import java.text.NumberFormat; -import java.util.Scanner; -public class AccountEngine { + +public class AccountTrans { private NumberFormat formatter; private Console c; - public AccountEngine() { + public AccountTrans() { this.c = new Console(); this.formatter = NumberFormat.getCurrencyInstance(); } diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index 2e4d9ad..53bd031 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -3,13 +3,13 @@ public class Menu { private UserAccount currentUser; private boolean loggedIn; private Console c; - private WelcomeEngine ls; - private AccountEngine ae; + private UserManagement ls; + private AccountTrans ae; public Menu() { this.c = new Console(); - this.ls = new WelcomeEngine(); - this.ae = new AccountEngine(); + this.ls = new UserManagement(); + this.ae = new AccountTrans(); this.loggedIn = false; this.currentUser = null; } diff --git a/src/main/java/UserAccount.java b/src/main/java/UserAccount.java index a2462a2..0db73a6 100644 --- a/src/main/java/UserAccount.java +++ b/src/main/java/UserAccount.java @@ -1,4 +1,3 @@ -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/WelcomeEngine.java b/src/main/java/UserManagement.java similarity index 97% rename from src/main/java/WelcomeEngine.java rename to src/main/java/UserManagement.java index 3a9379a..ea6c14e 100644 --- a/src/main/java/WelcomeEngine.java +++ b/src/main/java/UserManagement.java @@ -1,7 +1,6 @@ -import java.util.ArrayList; import java.util.HashMap; -public class WelcomeEngine { +public class UserManagement { Console c = new Console(); private String enteredUserName; @@ -9,7 +8,7 @@ public class WelcomeEngine { private HashMap userNamePasswordMap; private HashMap userAccountsList; - public WelcomeEngine() { + public UserManagement() { this.userNamePasswordMap = new HashMap(); // FOR TESTING this.userNamePasswordMap.put("TestAccount", "123"); diff --git a/src/main/test/LoginScreenTest.java b/src/main/test/LoginScreenTest.java index abbaedd..3f27a1d 100644 --- a/src/main/test/LoginScreenTest.java +++ b/src/main/test/LoginScreenTest.java @@ -1,7 +1,7 @@ public class LoginScreenTest { public void testLoginScreen() { - WelcomeEngine ls = new WelcomeEngine(); + UserManagement ls = new UserManagement(); } From 782063d2293ec8921722b72705b59e68cf554219 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 19:12:05 -0400 Subject: [PATCH 16/28] Some minor changes --- src/main/java/UserAccount.java | 16 +--- ...{AccountTest.java => BankAccountTest.java} | 0 .../{UserTest.java => UserAccountTest.java} | 73 +++---------------- ...creenTest.java => UserManagementTest.java} | 2 +- 4 files changed, 15 insertions(+), 76 deletions(-) rename src/main/test/{AccountTest.java => BankAccountTest.java} (100%) rename src/main/test/{UserTest.java => UserAccountTest.java} (81%) rename src/main/test/{LoginScreenTest.java => UserManagementTest.java} (74%) diff --git a/src/main/java/UserAccount.java b/src/main/java/UserAccount.java index 0db73a6..a8a8717 100644 --- a/src/main/java/UserAccount.java +++ b/src/main/java/UserAccount.java @@ -16,18 +16,6 @@ public UserAccount(String username, String password) { this.userBankAccounts.put("Investment", new BankAccount("Investment")); } - public void closeCheckingAccount() { - this.userBankAccounts.put("Checking", null); - } - - public void closeSavingsAccount() { - this.userBankAccounts.put("Savings", null); - } - - public void closeInvestmentAccount() { - this.userBankAccounts.put("Investment", null); - } - public BankAccount getCheckingAccount() { return this.userBankAccounts.get("Checking"); } @@ -44,4 +32,8 @@ public String getUsername() { return this.username; } + public String getPassword() { + return this.password; + } + } diff --git a/src/main/test/AccountTest.java b/src/main/test/BankAccountTest.java similarity index 100% rename from src/main/test/AccountTest.java rename to src/main/test/BankAccountTest.java diff --git a/src/main/test/UserTest.java b/src/main/test/UserAccountTest.java similarity index 81% rename from src/main/test/UserTest.java rename to src/main/test/UserAccountTest.java index 51eef4b..ed148bf 100644 --- a/src/main/test/UserTest.java +++ b/src/main/test/UserAccountTest.java @@ -1,70 +1,20 @@ - - - - - // Test the expected User class from ATM. -/* import org.testng.Assert; import org.testng.annotations.Test; -public class UserTest { - - - @Test // tests default constructor - public void nulleryConstructorTest() { - } - - @Test // tests default constructor - public void nulleryConstructorTestNeg() { - } - +public class UserAccountTest { +/* @Test // tests constructor for user with name & password public void constructorUserNamePWTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); - String actualUsername = testUser.getUsername(); - String actualPassword = testUser.getPassword; // *** finish writing this test body **** - } - - @Test // tests constructor for user with name & password - public void constructorUserNamePWTestNeg() { - } - - @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTest() { - } - - @Test // tests constructor for user with name, password & accounts array - public void constructorUserNamePWAcctsTestNeg() { - } - - @Test // method sets/resets username how to test: create user, pass in name arg, use set/reset method - // double check return is the new value you set it to, not the first argument that you - // passed in w/ get method - public void setUsernameTest() { - String expectedUsername = "User01"; - String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); - String newUsername = "User02"; - testUser.setUsername(newUsername); - String actualUsername = testUser.getUsername(); - - Assert.assertEquals(actualUsername, newUsername); - } - - @Test - public void setUsernameTestNeg() { - String expectedUsername = "User01"; - String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); - String newUsername = "User02"; - testUser.setUsername(newUsername); + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); String actualUsername = testUser.getUsername(); + String actualPassword = testUser.getPassword(); - Assert.assertEquals(actualUsername, newUsername); + Assert.assertEquals(expectedUsername, actualUsername); + Assert.assertEquals(expectedPassword, actualPassword); } @Test // method returns username how to test: pass in username value, check to make sure username returned @@ -72,7 +22,7 @@ public void setUsernameTestNeg() { public void getUsernameTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); String actualUsername = testUser.getUsername(); Assert.assertEquals(actualUsername, expectedUsername); @@ -82,7 +32,7 @@ public void getUsernameTest() { public void getUsernameTestNeg() { String expectedUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); String actualUsername = testUser.getUsername(); Assert.assertNotEquals(actualUsername, "unknown"); @@ -94,7 +44,7 @@ public void getUsernameTestNeg() { public void setPasswordTest() { String initialUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(initialUsername, expectedPassword); + UserAccount testUser = new UserAccount(initialUsername, expectedPassword); testUser.setPassword("121212"); String actualPassword = testUser.getPassword(); @@ -246,7 +196,4 @@ public void removeAccountTestNeg() { } - - -} -*/ \ No newline at end of file + */ \ No newline at end of file diff --git a/src/main/test/LoginScreenTest.java b/src/main/test/UserManagementTest.java similarity index 74% rename from src/main/test/LoginScreenTest.java rename to src/main/test/UserManagementTest.java index 3f27a1d..920a3fd 100644 --- a/src/main/test/LoginScreenTest.java +++ b/src/main/test/UserManagementTest.java @@ -1,4 +1,4 @@ -public class LoginScreenTest { +public class UserManagementTest { public void testLoginScreen() { UserManagement ls = new UserManagement(); From 0bed77d6e4206a043d31022a1873d6a207917f86 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sun, 14 Mar 2021 19:15:38 -0400 Subject: [PATCH 17/28] Contructor tests for Account class --- src/main/java/Account.java | 6 +- ...nscationHist.java => TransactionHist.java} | 6 +- src/main/test/AccountTest.java | 174 +++++++++++++----- src/main/test/TranscationHistTest.java | 34 ++++ 4 files changed, 168 insertions(+), 52 deletions(-) rename src/main/java/{TranscationHist.java => TransactionHist.java} (95%) create mode 100644 src/main/test/TranscationHistTest.java diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 500f545..f4f513f 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -13,10 +13,10 @@ public Account() { } // Create and instantiate checking Account objects - TranscationHist checking = new TranscationHist(); + TransactionHist checking = new TransactionHist(); // Create and instantiate checking Account objects - TranscationHist savings = new TranscationHist(); - TranscationHist TxnHistory = new TranscationHist(); + TransactionHist savings = new TransactionHist(); + TransactionHist TxnHistory = new TransactionHist(); NumberFormat formatter = NumberFormat.getCurrencyInstance(); private Console c; Scanner sc = new Scanner(System.in); diff --git a/src/main/java/TranscationHist.java b/src/main/java/TransactionHist.java similarity index 95% rename from src/main/java/TranscationHist.java rename to src/main/java/TransactionHist.java index d16d41b..8186393 100644 --- a/src/main/java/TranscationHist.java +++ b/src/main/java/TransactionHist.java @@ -1,11 +1,15 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -public class TranscationHist { +public class TransactionHist { String type; double balance; + public TransactionHist() { + + } + void setType(String accType) { diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java index a3c4ad1..3ee2ed1 100644 --- a/src/main/test/AccountTest.java +++ b/src/main/test/AccountTest.java @@ -1,85 +1,163 @@ -/* -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.testng.Assert; import org.testng.annotations.Test; -import static org.junit.Assert.assertEquals; +import java.util.Scanner; // Test the expected Account class from ATM. public class AccountTest { @Test - public void testA0() { - Account a = new Account(0.0); - assertEquals(0.0, a.balance(), 0.0001); - } + public void constructorCActTypeTest1() { // tests creation of checking account - type field + // Arrange + Account testAccount = new Account(); + System.out.println(testAccount.checking.type); + String givenCAcctType = "Checking"; + String returnedCAcctType = testAccount.checking.type; + Assert.assertEquals(givenCAcctType, returnedCAcctType); - @Test - public void testA00() { - Account a = new Account(10.0); - assertEquals(10.0, a.balance(), 0.0001); } @Test - public void testA01() { - Account a = new Account(0.0); - assertEquals(true, a.closeAccount()); + public void constructorCActBalTest2() { // tests creation of checking account - balance equals zero @ creation + // Arrange + Account testAccount = new Account(); + System.out.println(testAccount.checking.balance); + double givenCAcctBal = 0.00; + double returnedCAcctBal = testAccount.checking.balance; + Assert.assertEquals(givenCAcctBal, returnedCAcctBal); } @Test - public void testA02() { - Account a = new Account(10.0); - assertEquals(false, a.closeAccount()); + public void constructorTestSActType3() { // tests creation of savings account - type field + // Arrange + Account testAccount = new Account(); + System.out.println(testAccount.savings.type); + String givenSAcctType = "Savings"; + String returnedSAcctType = testAccount.savings.type; + Assert.assertEquals(givenSAcctType, returnedSAcctType); + } @Test - public void testA1() { - Account a = new Account(0.0); - a.deposit(100.0); - assertEquals(100.0, a.balance(), 0.0001); + public void constructorTestSActBal4() { // tests creation of savings account - balance equals zero @ creation + // Arrange + Account testAccount = new Account(); + System.out.println(testAccount.savings.balance); + double givenSAcctBal = 0.00; + double returnedSAcctBal = testAccount.savings.balance; + Assert.assertEquals(givenSAcctBal, returnedSAcctBal); + } @Test - public void testA2() { - Account a = new Account(10.0); - a.deposit(100.0); - assertEquals(110.0, a.balance(), 0.0001); + public void constructorTestTxHxType5() { // tests creation of transactionHistory - type + // Arrange + Account testAccount = new Account(); + System.out.println(testAccount.TxnHistory.type); + String givenTxHxType = "Transaction"; + String returnedTxHxType = testAccount.TxnHistory.type; + Assert.assertEquals(givenTxHxType, returnedTxHxType); + } @Test - public void testA3() { - Account a = new Account(200.0); - Double actual = a.withdraw(100.0); - assertEquals(100.0, actual, 0.0001); + public void depositMoneyTest1() { + // Arrange + Scanner sc = new Scanner(System.in); + Integer depAccount = sc.nextInt(1); + Account testAccount = new Account(); + testAccount.depositMoney(); + } @Test - public void testA4() { - Account a = new Account(0.0); - Double actual = a.withdraw(1.0); - assertEquals(0.0, actual, 0.0001); + public void withdrawMoneyTest1() { + } @Test - public void testA5() { - Account a = new Account(10.0); - Account b = new Account(0.0); - a.transfer(b, 10.0); - assertEquals(0.0, a.balance(), 0.0001); - assertEquals(10.0, b.balance(), 0.0001); + public void transferMoneyTest1() { + } @Test - public void testA6() { - Account a = new Account(10.0); - Account b = new Account(0.0); - a.transfer(b, 100.0); // nothing should happen - assertEquals(10.0, a.balance(), 0.0001); - assertEquals(0.0, b.balance(), 0.0001); + public void checkBalance1() { + } + + +// @Test +// public void testA0() { +// Account a = new Account(0.0); +// assertEquals(0.0, a.balance(), 0.0001); +// } +// +// @Test +// public void testA00() { +// Account a = new Account(10.0); +// assertEquals(10.0, a.balance(), 0.0001); +// } +// +// @Test +// public void testA01() { +// Account a = new Account(0.0); +// assertEquals(true, a.closeAccount()); +// } +// +// @Test +// public void testA02() { +// Account a = new Account(10.0); +// assertEquals(false, a.closeAccount()); +// } +// +// @Test +// public void testA1() { +// Account a = new Account(0.0); +// a.deposit(100.0); +// assertEquals(100.0, a.balance(), 0.0001); +// } +// +// @Test +// public void testA2() { +// Account a = new Account(10.0); +// a.deposit(100.0); +// assertEquals(110.0, a.balance(), 0.0001); +// } +// +// @Test +// public void testA3() { +// Account a = new Account(200.0); +// Double actual = a.withdraw(100.0); +// assertEquals(100.0, actual, 0.0001); +// } +// +// @Test +// public void testA4() { +// Account a = new Account(0.0); +// Double actual = a.withdraw(1.0); +// assertEquals(0.0, actual, 0.0001); +// } +// +// @Test +// public void testA5() { +// Account a = new Account(10.0); +// Account b = new Account(0.0); +// a.transfer(b, 10.0); +// assertEquals(0.0, a.balance(), 0.0001); +// assertEquals(10.0, b.balance(), 0.0001); +// } +// +// @Test +// public void testA6() { +// Account a = new Account(10.0); +// Account b = new Account(0.0); +// a.transfer(b, 100.0); // nothing should happen +// assertEquals(10.0, a.balance(), 0.0001); +// assertEquals(0.0, b.balance(), 0.0001); +// } + + } -*/ \ No newline at end of file diff --git a/src/main/test/TranscationHistTest.java b/src/main/test/TranscationHistTest.java new file mode 100644 index 0000000..b0728ee --- /dev/null +++ b/src/main/test/TranscationHistTest.java @@ -0,0 +1,34 @@ +import org.junit.Test; + +import static org.junit.Assert.*; + +public class TranscationHistTest { + + @Test + public void setType() { + } + + @Test + public void setBalance() { + } + + @Test + public void deposit() { + } + + @Test + public void withdraw() { + } + + @Test + public void getBalance() { + } + + @Test + public void printTxn() { + } + + @Test + public void dateTime() { + } +} \ No newline at end of file From 98d4eb84fea5ff1fcd0b889390daa0d97ee2ff16 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sun, 14 Mar 2021 20:23:54 -0400 Subject: [PATCH 18/28] initial commit after latest pull from remote master --- src/main/test/BankAccountTest.java | 79 +----------------------------- src/main/test/UserAccountTest.java | 4 +- 2 files changed, 2 insertions(+), 81 deletions(-) diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 3ee2ed1..612532c 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -1,90 +1,13 @@ -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Scanner; // Test the expected Account class from ATM. -public class AccountTest { - - @Test - public void constructorCActTypeTest1() { // tests creation of checking account - type field - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.type); - String givenCAcctType = "Checking"; - String returnedCAcctType = testAccount.checking.type; - Assert.assertEquals(givenCAcctType, returnedCAcctType); - - } - - @Test - public void constructorCActBalTest2() { // tests creation of checking account - balance equals zero @ creation - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.balance); - double givenCAcctBal = 0.00; - double returnedCAcctBal = testAccount.checking.balance; - Assert.assertEquals(givenCAcctBal, returnedCAcctBal); - } - - @Test - public void constructorTestSActType3() { // tests creation of savings account - type field - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.savings.type); - String givenSAcctType = "Savings"; - String returnedSAcctType = testAccount.savings.type; - Assert.assertEquals(givenSAcctType, returnedSAcctType); - - } - - @Test - public void constructorTestSActBal4() { // tests creation of savings account - balance equals zero @ creation - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.savings.balance); - double givenSAcctBal = 0.00; - double returnedSAcctBal = testAccount.savings.balance; - Assert.assertEquals(givenSAcctBal, returnedSAcctBal); - - } - - @Test - public void constructorTestTxHxType5() { // tests creation of transactionHistory - type - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.TxnHistory.type); - String givenTxHxType = "Transaction"; - String returnedTxHxType = testAccount.TxnHistory.type; - Assert.assertEquals(givenTxHxType, returnedTxHxType); - - } - - @Test - public void depositMoneyTest1() { - // Arrange - Scanner sc = new Scanner(System.in); - Integer depAccount = sc.nextInt(1); - Account testAccount = new Account(); - testAccount.depositMoney(); - - } +public class BankAccountTest { - @Test - public void withdrawMoneyTest1() { - } - @Test - public void transferMoneyTest1() { - } - @Test - public void checkBalance1() { - } diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index ed148bf..756b494 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -1,9 +1,7 @@ // Test the expected User class from ATM. -import org.testng.Assert; -import org.testng.annotations.Test; -public class UserAccountTest { +public class UserAccountTest {} /* @Test // tests constructor for user with name & password public void constructorUserNamePWTest() { From 82563167d71fa5a27be4fe387fd222dcd6fa0f75 Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sun, 14 Mar 2021 21:05:52 -0400 Subject: [PATCH 19/28] checkpointing: BankAccount class method tests 60% complete --- src/main/java/BankAccount.java | 14 ++-- src/main/test/BankAccountTest.java | 102 ++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 7 deletions(-) diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index 355e3ce..ba62795 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -1,14 +1,13 @@ import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Map; public class BankAccount { - private String accountType; + public String accountType; private double currentBalance; NumberFormat formatter = NumberFormat.getCurrencyInstance(); @@ -22,10 +21,17 @@ public BankAccount(String chosenAccountType) { void setType(String accType) { accountType = accType; } + void setBalance(Double accBal) { currentBalance = accBal; } + public String getAccountType() { return accountType; } + + Double getBalance() { + return currentBalance; + } + void deposit(Double dep) { currentBalance = currentBalance + dep; } @@ -34,10 +40,6 @@ void withdraw(Double wit) { currentBalance = currentBalance - wit; } - Double getBalance() { - return currentBalance; - } - void printTxn(String txnType, Double amt, Double balance){ System.out.println(""); diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 612532c..0cbc8ac 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -1,17 +1,117 @@ - +import org.junit.Test; +import org.testng.Assert; // Test the expected Account class from ATM. public class BankAccountTest { + @Test + public void constructorInitialBalanceTest1() { // tests account balance 0.0 upon creation of BankAccount + //Arrange + String givenAccountType = "Checking"; + Double givenCurrentBalance = 0.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + Double returnedBalance = testBankAccount.getBalance(); + //Assert + Assert.assertEquals(givenCurrentBalance, returnedBalance); + } + + @Test + public void constructorAcctTypeArgTest2() { // tests creation of BankAccount sets account type + //Arrange + String givenAccountType = "Checking"; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + String returnedAccountType = testBankAccount.accountType; + //Assert + Assert.assertEquals(givenAccountType, returnedAccountType); + + } + + @Test + public void setTypeTest() { // tests method to reset account type + //Arrange + String givenAccountType = "Checking"; + Double givenCurrentBalance = 0.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + testBankAccount.setType("Savings"); + String returnedAccountType = testBankAccount.getAccountType(); + //Assert + Assert.assertEquals(givenAccountType, returnedAccountType); + } + + @Test + public void getAccountTypeTest() { // tests method for return account type + //Arrange + String givenAccountType = "Checking"; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + String returnedAccountType = testBankAccount.getAccountType(); + //Assert + Assert.assertEquals(givenAccountType, returnedAccountType); + } + @Test + public void setBalanceTest() { // tests method to reset account balance + //Arrange + String givenAccountType = "Investment"; + Double givenCurrentBalance = 0.0; + Double expectedAccountBal = 100.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + testBankAccount.setBalance(100.0); + Double returnedAccountBal = testBankAccount.getBalance(); + //Assert + Assert.assertEquals(expectedAccountBal, returnedAccountBal); + } + @Test + public void getBalanceTest() { // tests method to reset account balance + //Arrange + String givenAccountType = "Investment"; + Double givenCurrentBalance = 0.0; + Double expectedAccountBal = 100.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + testBankAccount.setBalance(100.0); + Double returnedAccountBal = testBankAccount.getBalance(); + //Assert + Assert.assertEquals(expectedAccountBal, returnedAccountBal); + } + @Test + public void depositTest() { + } + @Test + public void withdrawTest() { + } + @Test + public void printTxnTest() { + } + + @Test + public void dateTimeTest() { + //Arrange + String givenAccountType = "Checking"; + //Act + BankAccount testBankAccount1 = new BankAccount(givenAccountType); + BankAccount testBankAccount2 = new BankAccount(givenAccountType); + System.out.println(testBankAccount1.dateTime()); + System.out.println(testBankAccount2.dateTime()); + String expectedDateTime = testBankAccount1.dateTime(); + String returnedDateTime = testBankAccount2.dateTime(); + //Assert + Assert.assertEquals(expectedDateTime, returnedDateTime); +} + + // @Test // public void testA0() { // Account a = new Account(0.0); From 1759214e5a6ea361b37edddbb9ad5e1c10f17261 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 22:10:49 -0400 Subject: [PATCH 20/28] Added unit tests for UserManagement class --- src/main/java/AccountTrans.java | 22 +++++----- src/main/java/BankAccount.java | 3 ++ src/main/java/UserManagement.java | 36 ++++++++++------ src/main/test/BankAccountTest.java | 6 ++- src/main/test/ConsoleTest.java | 18 ++++++++ src/main/test/TranscationHistTest.java | 8 ++-- src/main/test/UserAccountTest.java | 4 +- src/main/test/UserManagementTest.java | 60 +++++++++++++++++++++++++- 8 files changed, 123 insertions(+), 34 deletions(-) diff --git a/src/main/java/AccountTrans.java b/src/main/java/AccountTrans.java index b2d52d0..2b04dac 100644 --- a/src/main/java/AccountTrans.java +++ b/src/main/java/AccountTrans.java @@ -13,7 +13,7 @@ public AccountTrans() { public void depositMoney(BankAccount chosenBankAccount) { // Keeps track of which account to deposit money to - checking or saving - System.out.println("\nYour current Savings balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + System.out.println("\nYour current " + chosenBankAccount.getAccountType() + " balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); System.out.println("How much money would you like to deposit?"); Double deposit; @@ -22,15 +22,15 @@ public void depositMoney(BankAccount chosenBankAccount) { System.out.println("Please enter amount greater than ZERO"); } else { chosenBankAccount.deposit(deposit); - System.out.println("\nYour Savings balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); - chosenBankAccount.printTxn("Savings Deposit ", deposit, chosenBankAccount.getBalance()); + System.out.println("\nYour " + chosenBankAccount.getAccountType() + " balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + chosenBankAccount.printTxn(chosenBankAccount.getAccountType() + " Deposit ", deposit, chosenBankAccount.getBalance()); System.out.println(); } } public void withdrawMoney(BankAccount chosenBankAccount) { - System.out.println("\nYour current Savings balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + System.out.println("\nYour current " + chosenBankAccount.getAccountType() + " balance is: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); System.out.println("How much money would you like to withdraw?"); Double withdraw; @@ -39,15 +39,15 @@ public void withdrawMoney(BankAccount chosenBankAccount) { System.out.println("INSUFFICIENT BALANCE! Your request will not be processed. \n"); } else { chosenBankAccount.withdraw(withdraw); - System.out.println("\nYour Savings balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); - chosenBankAccount.printTxn("Savings withdraw ", withdraw, chosenBankAccount.getBalance() ); + System.out.println("\nYour " + chosenBankAccount.getAccountType() + " balance is now: " + formatter.format(chosenBankAccount.getBalance()) + "\n"); + chosenBankAccount.printTxn(chosenBankAccount.getAccountType() + " withdraw ", withdraw, chosenBankAccount.getBalance() ); System.out.println(); } } public void transferMoney(BankAccount chosenTransferFromAccount, BankAccount chosenTransferToAccount) { - System.out.println("\nYour current Savings balance is: " + formatter.format(chosenTransferFromAccount.getBalance()) + "\n"); - System.out.print("How much money do you wish to transfer from Savings to Checking?: "); + System.out.println("\nYour current " + chosenTransferFromAccount.getAccountType() + " balance is: " + formatter.format(chosenTransferFromAccount.getBalance()) + "\n"); + System.out.print("How much money do you wish to transfer from " + chosenTransferFromAccount.getAccountType() + " to " + chosenTransferToAccount.getAccountType() + "?: "); Double tranAmount; tranAmount = c.getDoubleInput(); @@ -57,9 +57,9 @@ public void transferMoney(BankAccount chosenTransferFromAccount, BankAccount cho chosenTransferFromAccount.withdraw(tranAmount); chosenTransferToAccount.deposit(tranAmount); - System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from Savings to Checking"); - System.out.println("\nChecking Balance: " + formatter.format(chosenTransferFromAccount.getBalance())); - System.out.println("Savings Balance: " + formatter.format(chosenTransferToAccount.getBalance()) + "\n"); + System.out.println("\nYou successfully transferred " + formatter.format(tranAmount) + " from " + chosenTransferFromAccount.getAccountType() + " to " + chosenTransferToAccount.getAccountType()); + System.out.println("\n" + chosenTransferFromAccount.getAccountType() + " Balance: " + formatter.format(chosenTransferFromAccount.getBalance())); + System.out.println(chosenTransferToAccount.getAccountType() + " Balance: " + formatter.format(chosenTransferToAccount.getBalance()) + "\n"); } } diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index 355e3ce..4587803 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -25,6 +25,9 @@ void setType(String accType) { void setBalance(Double accBal) { currentBalance = accBal; } + public String getAccountType() { + return this.accountType; + } void deposit(Double dep) { currentBalance = currentBalance + dep; diff --git a/src/main/java/UserManagement.java b/src/main/java/UserManagement.java index ea6c14e..663d758 100644 --- a/src/main/java/UserManagement.java +++ b/src/main/java/UserManagement.java @@ -10,41 +10,48 @@ public class UserManagement { public UserManagement() { this.userNamePasswordMap = new HashMap(); - // FOR TESTING - this.userNamePasswordMap.put("TestAccount", "123"); - this.userNamePasswordMap.put("TestAccount2", "456"); + this.userAccountsList = new HashMap(); + } + // Need this one for testing + public UserManagement(String username, String password) { + this.userNamePasswordMap = new HashMap(); this.userAccountsList = new HashMap(); - // FOR TESTING - userAccountsList.put("TestAccount", new UserAccount("TestAccount", "123")); - userAccountsList.put("TestAccount2", new UserAccount("TestAccount2", "456")); + this.enteredPassword = password; + this.enteredUserName = username; + } + + // Need this one for testing + public HashMap getUserNamePasswordMap() { + return this.userNamePasswordMap; } - public String getEnteredUserName() { - return this.enteredUserName; + // Need this one for testing + public HashMap getUserAccountsList() { + return this.userAccountsList; } - public void getUserName() { + public void getInputUserName() { System.out.println("Username:"); this.enteredUserName = c.getStringInput(); } - public void getPassword() { - System.out.println("Password"); + public void getInputPassword() { + System.out.println("Password:"); this.enteredPassword = c.getStringInput(); } public boolean validateUserNameExists() { - this.getUserName(); return this.userNamePasswordMap.containsKey(this.enteredUserName); } public boolean validatePasswordCorrect() { - this.getPassword(); return this.userNamePasswordMap.get(this.enteredUserName).equals(this.enteredPassword); } public UserAccount validateLoginCredentials() { + getInputUserName(); + getInputPassword(); if(this.validateUserNameExists() == false) { System.out.println("No such user exists."); } else if (this.validatePasswordCorrect() == false) { @@ -59,10 +66,11 @@ public UserAccount validateLoginCredentials() { public UserAccount createNewUserAccount() { System.out.println("Enter your new username and password."); + getInputUserName(); int attempts = 0; while (attempts < 3) { if (this.validateUserNameExists() == false) { - getPassword(); + getInputPassword(); setUpUserAccount(); System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!"); return userAccountsList.get(this.enteredUserName); diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 3ee2ed1..160bc8b 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -5,8 +5,8 @@ // Test the expected Account class from ATM. -public class AccountTest { - +public class BankAccountTest { +/* @Test public void constructorCActTypeTest1() { // tests creation of checking account - type field // Arrange @@ -86,6 +86,8 @@ public void checkBalance1() { } + */ + diff --git a/src/main/test/ConsoleTest.java b/src/main/test/ConsoleTest.java index c65607c..8edb008 100644 --- a/src/main/test/ConsoleTest.java +++ b/src/main/test/ConsoleTest.java @@ -1,5 +1,23 @@ +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + public class ConsoleTest { + @Test + public void testStringInput() { + InputStream sysInBackup = System.in; // backup System.in to restore it later + ByteArrayInputStream in = new ByteArrayInputStream("1".getBytes()); + System.setIn(in); + + Console c = new Console(); + String actual = c.getStringInput(); + + Assert.assertEquals( actual, "1"); + System.setIn(sysInBackup); + } } diff --git a/src/main/test/TranscationHistTest.java b/src/main/test/TranscationHistTest.java index b0728ee..9864e74 100644 --- a/src/main/test/TranscationHistTest.java +++ b/src/main/test/TranscationHistTest.java @@ -1,9 +1,9 @@ -import org.junit.Test; +//import org.junit.Test; -import static org.junit.Assert.*; +//import static org.junit.Assert.*; public class TranscationHistTest { - +/* @Test public void setType() { } @@ -31,4 +31,6 @@ public void printTxn() { @Test public void dateTime() { } + */ + } \ No newline at end of file diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index ed148bf..aa8b3dd 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -193,7 +193,7 @@ public void removeAccountTestNeg() { Assert.assertNotEquals(actualArrString, 5); } + */ -} - */ \ No newline at end of file +} diff --git a/src/main/test/UserManagementTest.java b/src/main/test/UserManagementTest.java index 920a3fd..ef64f88 100644 --- a/src/main/test/UserManagementTest.java +++ b/src/main/test/UserManagementTest.java @@ -1,8 +1,64 @@ +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.HashMap; + public class UserManagementTest { - public void testLoginScreen() { - UserManagement ls = new UserManagement(); + @Test + public void testConstructor() { + UserManagement um = new UserManagement("TestAccount", "123"); + + String actual = (String) um.getUserAccountsList().get("TestAccount"); + String actual2 = (String) um.getUserNamePasswordMap().get("TestAccount"); + + Assert.assertEquals(actual, null); + } + + @Test + public void testValidateUserNameExists() { + UserManagement um = new UserManagement("TestAccount", "123"); + + um.setUpUserAccount(); + boolean actual = um.validateUserNameExists(); + + Assert.assertTrue(actual); + } + + @Test + public void testValidatePasswordCorrect() { + UserManagement um = new UserManagement("TestAccount", "123"); + um.setUpUserAccount(); + boolean actual = um.validatePasswordCorrect(); + Assert.assertTrue(actual); } + + @Test + public void setUpUserAccount() { + UserManagement um = new UserManagement("TestAccount", "123"); + + um.setUpUserAccount(); + boolean actualPass = um.validatePasswordCorrect(); + boolean actualUN = um.validateUserNameExists(); + + Assert.assertTrue(actualPass); + Assert.assertTrue(actualUN); + } + + @Test + public void closeUserAccount() { + UserManagement um = new UserManagement("TestAccount", "123"); + + um.setUpUserAccount(); + um.closeAccount(); + + String actual = (String) um.getUserNamePasswordMap().get("TestAccount"); + String actual2 = (String) um.getUserAccountsList().get("TestAccount"); + + Assert.assertEquals(actual, null); + Assert.assertEquals(actual2, null); + } + } From 5b91ec2be1a34b6151e2c5bc08cfe17e775129dd Mon Sep 17 00:00:00 2001 From: KellyPorter02 Date: Sun, 14 Mar 2021 22:21:56 -0400 Subject: [PATCH 21/28] tests for BankAccount complete --- src/main/java/BankAccount.java | 10 +++++----- src/main/test/BankAccountTest.java | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index ba62795..bb33658 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -42,16 +42,16 @@ void withdraw(Double wit) { void printTxn(String txnType, Double amt, Double balance){ - System.out.println(""); + System.out.println("|----------------------------------------|"); System.out.println("| BANK OF ZIP CODE WILMINGTON DE |"); System.out.println("|----------------------------------------|"); System.out.println("|" + dateTime() + " "+"|"); System.out.println("|----------------------------------------|"); - System.out.println("| Transaction Receipt |"); - System.out.println("|" + txnType + " " +"|"); - System.out.println("|" + amt + "" + " "+ "|"); - System.out.println("| Remaining Balance: " + balance + " " + "|"); + System.out.println("| Transaction Receipt |"); + System.out.println("|" + txnType + " " +"|"); + System.out.println("|" + amt + "" + " "+ "|"); + System.out.println("| Remaining Balance: " + balance + " " + "|"); System.out.println("|----------------------------------------|"); } diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 0cbc8ac..d89dd67 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -84,20 +84,34 @@ public void getBalanceTest() { // tests method to reset account balance @Test public void depositTest() { + //Arrange + String givenAccountType = "Investment"; + Double expectedAccountBal = 200.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + testBankAccount.setBalance(100.00); + testBankAccount.deposit(100.0); + Double returnedAccountBalance = testBankAccount.getBalance(); + //Assert + Assert.assertEquals(expectedAccountBal, returnedAccountBalance); } @Test public void withdrawTest() { - } - - - - @Test - public void printTxnTest() { + //Arrange + String givenAccountType = "Investment"; + Double expectedAccountBal = 0.0; + //Act + BankAccount testBankAccount = new BankAccount(givenAccountType); + testBankAccount.setBalance(100.00); + testBankAccount.withdraw(100.0); + Double returnedAccountBalance = testBankAccount.getBalance(); + //Assert + Assert.assertEquals(expectedAccountBal, returnedAccountBalance); } @Test - public void dateTimeTest() { + public void dateTimeTest() { // tests return of date and time method //Arrange String givenAccountType = "Checking"; //Act From f10f80540f9939586f6cbbd9972b5168b71ab5b4 Mon Sep 17 00:00:00 2001 From: Theresa Date: Sun, 14 Mar 2021 22:26:48 -0400 Subject: [PATCH 22/28] Added some UserAccount unit tests --- src/main/test/UserAccountTest.java | 163 +++++------------------------ 1 file changed, 29 insertions(+), 134 deletions(-) diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index aa8b3dd..d8d4c0d 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -4,9 +4,9 @@ import org.testng.annotations.Test; public class UserAccountTest { -/* + @Test // tests constructor for user with name & password - public void constructorUserNamePWTest() { + public void testGetConstructorUserNamePWTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); @@ -19,7 +19,7 @@ public void constructorUserNamePWTest() { @Test // method returns username how to test: pass in username value, check to make sure username returned // is same as what you passed in - public void getUsernameTest() { + public void testGetUsernameTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); @@ -29,7 +29,7 @@ public void getUsernameTest() { } @Test - public void getUsernameTestNeg() { + public void testGetUsernameTestNeg() { String expectedUsername = "User01"; String expectedPassword = "password123"; UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); @@ -38,162 +38,57 @@ public void getUsernameTestNeg() { Assert.assertNotEquals(actualUsername, "unknown"); } - @Test // method sets/resets password how to test: create user, pass in pw arg, use set/reset method - // double check return is the new value you set it to, not the first argument that you - // passed in w/ get method - public void setPasswordTest() { - String initialUsername = "User01"; - String expectedPassword = "password123"; - UserAccount testUser = new UserAccount(initialUsername, expectedPassword); - testUser.setPassword("121212"); - String actualPassword = testUser.getPassword(); - - - Assert.assertEquals(actualPassword, "121212"); - } - - @Test - public void setPasswordTestNeg() { - String initialUsername = "User01"; - String expectedPassword = "password123"; - User testUser = new User(initialUsername, expectedPassword); - testUser.setPassword("121212"); - String actualPassword = testUser.getPassword(); - - Assert.assertNotEquals(actualPassword, initialUsername); - } - @Test // method returns password how to test: pass in username value, check to make sure username returned // is same as what you passed in - public void getPasswordTest() { + public void testGetPasswordTest() { String expectedUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); String actualPassword = testUser.getPassword(); Assert.assertEquals(actualPassword, expectedPassword); } @Test - public void getPasswordTestNeg() { + public void testGetPasswordTestNeg() { String expectedUsername = "User01"; String expectedPassword = "password123"; - User testUser = new User(expectedUsername, expectedPassword); + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); String actualPassword = testUser.getPassword(); Assert.assertNotEquals(actualPassword, "Unknown"); } - @Test // method returns user's array of accounts how to test: check to make sure accounts array returned - // (return as a string with .toString method) convert original accounts array to string - // matches original, passed in array make array use .toString method on it - // need accounts constructor to make multiple instances of accounts, pass into array, pass array into - // constructor of user - public void getAccountsArrayTest() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3}; - String initialArrString = accountsArr.toString(); - User testUser = new User("User01", "password123", accountsArr); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertEquals(actualArrString, initialArrString); - - } - @Test - public void getAccountsArrayTestNeg() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3}; - String initialArrString = accountsArr.toString(); - User testUser = new User("User01", "password123", accountsArr); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertNotEquals(actualArrString, "5"); - } + public void testGetCheckingAccount() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); - @Test // method adds account to user's array of accounts how to test: check to make sure accounts array returns - // initial accounts array passed in - // (return as a string with .toString method) convert original accounts array to string - // matches original, passed in array make array use .toString method on it - // use .addAccount method, pass in account to add - // change output array to string, compare strings to strings - // save expected string to variable to pass in for expected assert type in your expected string - // need accounts constructor to make multiple instances of accounts, pass into array, pass array into - // constructor of user - public void addAccountTest() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account account4 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3}; - String initialArrString = accountsArr.toString(); - User testUser = new User("User01", "password123", accountsArr); - testUser.addAccount(accounts, account4); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertEquals(actualArrString, initialArrString); + String actual = testUser.getCheckingAccount().getAccountType(); + + Assert.assertEquals(actual, "Checking"); } @Test - public void addAccountTestNeg() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account account4 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3}; - String initialArrString = accountsArr.toString(); - User testUser = new User("User01", "password123", accountsArr); - testUser.addAccount(accounts, account4); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertNotEquals( actualArrString, 5); - } + public void testGetSavingsAccount() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); - @Test // method adds account to user's array of accounts how to test: check to make sure accounts array returns - // initial accounts array passed in - // (return as a string with .toString method) convert original accounts array to string - // matches original, passed in array make array use .toString method on it - // use .addAccount method, pass in account to add - // change output array to string, compare strings to strings - // save expected string to variable to pass in for expected assert type in your expected string - // need accounts constructor to make multiple instances of accounts, pass into array, pass array into - // constructor of user - public void removeAccountTest() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account account4 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3, account4}; - Account[] expectedArr = {account1, account3, account4}; - String expectedArrString = expectedArr - User testUser = new User("User01", "password123", accountsArr); - testUser.removeAccount(accounts, account2); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertEquals(actualArrString, expectedArrString); - } + String actual = testUser.getSavingsAccount().getAccountType(); - @Test - public void removeAccountTestNeg() { - Account account1 = new Account(accountNumber, availableBalance); - Account account2 = new Account(accountNumber, availableBalance); - Account account3 = new Account(accountNumber, availableBalance); - Account account4 = new Account(accountNumber, availableBalance); - Account[] accountsArr = {account1, account2, account3, account4}; - Account[] expectedArr = {account1, account3, account4}; - String expectedArrString = expectedArr - User testUser = new User("User01", "password123", accountsArr); - testUser.removeAccount(accounts, account2); - String actualArrString = accountsArr.toString(accountsArr.getAccounts()); - - Assert.assertNotEquals(actualArrString, 5); + Assert.assertEquals(actual, "Savings"); } - */ + @Test + public void testGetInvestmentAccount() { + String expectedUsername = "User01"; + String expectedPassword = "password123"; + UserAccount testUser = new UserAccount(expectedUsername, expectedPassword); + String actual = testUser.getInvestmentAccount().getAccountType(); + Assert.assertEquals(actual, "Investment"); + } } From 1665f322a3ea91133cbcc6a5bd4d8d916b3abc72 Mon Sep 17 00:00:00 2001 From: theresa-mashura <78986299+theresa-mashura@users.noreply.github.com> Date: Sun, 14 Mar 2021 22:32:44 -0400 Subject: [PATCH 23/28] Update BankAccountTest.java --- src/main/test/BankAccountTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index c8c9083..1088366 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -3,7 +3,7 @@ // Test the expected Account class from ATM. public class BankAccountTest { -/* + @Test public void constructorCActTypeTest1() { // tests creation of checking account - type field // Arrange From 002de7559ad48f08ed9f8553f5d56edc162f2e72 Mon Sep 17 00:00:00 2001 From: Monali Date: Sun, 14 Mar 2021 22:46:45 -0400 Subject: [PATCH 24/28] Latest changes --- pom.xml | 11 -- src/main/java/AccountTrans.java | 7 -- src/main/java/BankAccount.java | 2 - src/main/java/Menu.java | 1 + src/main/test/BankAccountTest.java | 165 ++++++++++++------------- src/main/test/ConsoleTest.java | 4 - src/main/test/TranscationHistTest.java | 34 ----- src/main/test/UserAccountTest.java | 4 +- 8 files changed, 83 insertions(+), 145 deletions(-) delete mode 100644 src/main/test/TranscationHistTest.java diff --git a/pom.xml b/pom.xml index a4cd34c..3187db7 100644 --- a/pom.xml +++ b/pom.xml @@ -13,13 +13,8 @@ org.apache.maven.plugins maven-compiler-plugin -<<<<<<< HEAD - 8 - 8 -======= 11 11 ->>>>>>> master @@ -31,12 +26,6 @@ RELEASE test - - org.junit.jupiter - junit-jupiter - RELEASE - compile - diff --git a/src/main/java/AccountTrans.java b/src/main/java/AccountTrans.java index b2d52d0..e35f031 100644 --- a/src/main/java/AccountTrans.java +++ b/src/main/java/AccountTrans.java @@ -72,11 +72,4 @@ public void checkBalance (UserAccount currentUser) { } -/// //Time display -// public static void getTime(){ -// DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); -// LocalDateTime now = LocalDateTime.now(); -// displayValue = (timeFormat.format(now)); -// } -///add switch case 6 for other options : create new account, close account, print transaction receipt diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index 355e3ce..2a90bc1 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -1,7 +1,6 @@ import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Map; @@ -57,7 +56,6 @@ String dateTime(){ DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); - //System.out.println (timeFormat.format(now)); return timeFormat.format(now); } diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index 53bd031..00d7572 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -48,6 +48,7 @@ public void printWelcomeMenu() { if (this.currentUser != null) { this.loggedIn = true; } + break; default: System.out.println("Invalid input. Please select either 1 or 2."); } diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 3ee2ed1..444e8d0 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -1,90 +1,87 @@ -import org.testng.Assert; -import org.testng.annotations.Test; -import java.util.Scanner; // Test the expected Account class from ATM. -public class AccountTest { - - @Test - public void constructorCActTypeTest1() { // tests creation of checking account - type field - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.type); - String givenCAcctType = "Checking"; - String returnedCAcctType = testAccount.checking.type; - Assert.assertEquals(givenCAcctType, returnedCAcctType); - - } - - @Test - public void constructorCActBalTest2() { // tests creation of checking account - balance equals zero @ creation - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.balance); - double givenCAcctBal = 0.00; - double returnedCAcctBal = testAccount.checking.balance; - Assert.assertEquals(givenCAcctBal, returnedCAcctBal); - } - - @Test - public void constructorTestSActType3() { // tests creation of savings account - type field - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.savings.type); - String givenSAcctType = "Savings"; - String returnedSAcctType = testAccount.savings.type; - Assert.assertEquals(givenSAcctType, returnedSAcctType); - - } - - @Test - public void constructorTestSActBal4() { // tests creation of savings account - balance equals zero @ creation - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.savings.balance); - double givenSAcctBal = 0.00; - double returnedSAcctBal = testAccount.savings.balance; - Assert.assertEquals(givenSAcctBal, returnedSAcctBal); - - } - - @Test - public void constructorTestTxHxType5() { // tests creation of transactionHistory - type - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.TxnHistory.type); - String givenTxHxType = "Transaction"; - String returnedTxHxType = testAccount.TxnHistory.type; - Assert.assertEquals(givenTxHxType, returnedTxHxType); - - } - - @Test - public void depositMoneyTest1() { - // Arrange - Scanner sc = new Scanner(System.in); - Integer depAccount = sc.nextInt(1); - Account testAccount = new Account(); - testAccount.depositMoney(); - - } - - @Test - public void withdrawMoneyTest1() { - - } - - @Test - public void transferMoneyTest1() { - - } - - @Test - public void checkBalance1() { - - } +//public class BankAccountTest { +// +// @Test +// public void constructorCActTypeTest1() { // tests creation of checking account - type field +// // Arrange +// Account testAccount = new Account(); +// System.out.println(testAccount.checking.type); +// String givenCAcctType = "Checking"; +// String returnedCAcctType = testAccount.checking.type; +// Assert.assertEquals(givenCAcctType, returnedCAcctType); +// +// } +// +// @Test +// public void constructorCActBalTest2() { // tests creation of checking account - balance equals zero @ creation +// // Arrange +// Account testAccount = new Account(); +// System.out.println(testAccount.checking.balance); +// double givenCAcctBal = 0.00; +// double returnedCAcctBal = testAccount.checking.balance; +// Assert.assertEquals(givenCAcctBal, returnedCAcctBal); +// } +// +// @Test +// public void constructorTestSActType3() { // tests creation of savings account - type field +// // Arrange +// Account testAccount = new Account(); +// System.out.println(testAccount.savings.type); +// String givenSAcctType = "Savings"; +// String returnedSAcctType = testAccount.savings.type; +// Assert.assertEquals(givenSAcctType, returnedSAcctType); +// +// } +// +// @Test +// public void constructorTestSActBal4() { // tests creation of savings account - balance equals zero @ creation +// // Arrange +// Account testAccount = new Account(); +// System.out.println(testAccount.savings.balance); +// double givenSAcctBal = 0.00; +// double returnedSAcctBal = testAccount.savings.balance; +// Assert.assertEquals(givenSAcctBal, returnedSAcctBal); +// +// } +// +// @Test +// public void constructorTestTxHxType5() { // tests creation of transactionHistory - type +// // Arrange +// Account testAccount = new Account(); +// System.out.println(testAccount.TxnHistory.type); +// String givenTxHxType = "Transaction"; +// String returnedTxHxType = testAccount.TxnHistory.type; +// Assert.assertEquals(givenTxHxType, returnedTxHxType); +// +// } +// +// @Test +// public void depositMoneyTest1() { +// // Arrange +// Scanner sc = new Scanner(System.in); +// Integer depAccount = sc.nextInt(1); +// Account testAccount = new Account(); +// testAccount.depositMoney(); +// +// } +// +// @Test +// public void withdrawMoneyTest1() { +// +// } +// +// @Test +// public void transferMoneyTest1() { +// +// } +// +// @Test +// public void checkBalance1() { +// +// } @@ -160,4 +157,4 @@ public void checkBalance1() { // } -} +//} diff --git a/src/main/test/ConsoleTest.java b/src/main/test/ConsoleTest.java index c65607c..8b13789 100644 --- a/src/main/test/ConsoleTest.java +++ b/src/main/test/ConsoleTest.java @@ -1,5 +1 @@ -public class ConsoleTest { - - -} diff --git a/src/main/test/TranscationHistTest.java b/src/main/test/TranscationHistTest.java deleted file mode 100644 index b0728ee..0000000 --- a/src/main/test/TranscationHistTest.java +++ /dev/null @@ -1,34 +0,0 @@ -import org.junit.Test; - -import static org.junit.Assert.*; - -public class TranscationHistTest { - - @Test - public void setType() { - } - - @Test - public void setBalance() { - } - - @Test - public void deposit() { - } - - @Test - public void withdraw() { - } - - @Test - public void getBalance() { - } - - @Test - public void printTxn() { - } - - @Test - public void dateTime() { - } -} \ No newline at end of file diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index ed148bf..e59ea0f 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -1,9 +1,7 @@ // Test the expected User class from ATM. -import org.testng.Assert; -import org.testng.annotations.Test; -public class UserAccountTest { +//public class UserAccountTest { /* @Test // tests constructor for user with name & password public void constructorUserNamePWTest() { From b598f8dc0b909226c9307c46add9f36aa3998ea8 Mon Sep 17 00:00:00 2001 From: Theresa Date: Mon, 15 Mar 2021 00:14:16 -0400 Subject: [PATCH 25/28] A couple small changes to tests --- pom.xml | 48 ++++++++++++++++++++++++++++++ src/main/java/BankAccount.java | 3 +- src/main/test/BankAccountTest.java | 11 ++++--- src/main/test/ConsoleTest.java | 3 +- src/main/test/UserAccountTest.java | 3 ++ 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index a4cd34c..2baebb9 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,54 @@ RELEASE compile + + junit + junit + 4.13.2 + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index 2efe059..bb388c2 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -25,12 +25,11 @@ void setType(String accType) { void setBalance(Double accBal) { currentBalance = accBal; } + public String getAccountType() { return this.accountType; } - public String getAccountType() { return accountType; } - Double getBalance() { return currentBalance; } diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index 1088366..722f9a7 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -1,4 +1,4 @@ -import org.junit.Test; +import org.testng.annotations.Test; import org.testng.Assert; // Test the expected Account class from ATM. @@ -7,12 +7,11 @@ public class BankAccountTest { @Test public void constructorCActTypeTest1() { // tests creation of checking account - type field // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.type); + BankAccount testAccount = new BankAccount("Checking"); String givenCAcctType = "Checking"; - String returnedCAcctType = testAccount.checking.type; + String returnedCAcctType = testAccount.getAccountType(); Assert.assertEquals(givenCAcctType, returnedCAcctType); - + } @Test public void constructorInitialBalanceTest1() { // tests account balance 0.0 upon creation of BankAccount @@ -48,7 +47,7 @@ public void setTypeTest() { // tests method to reset account type testBankAccount.setType("Savings"); String returnedAccountType = testBankAccount.getAccountType(); //Assert - Assert.assertEquals(givenAccountType, returnedAccountType); + Assert.assertEquals("Savings", returnedAccountType); } @Test diff --git a/src/main/test/ConsoleTest.java b/src/main/test/ConsoleTest.java index 8edb008..6b5e4b1 100644 --- a/src/main/test/ConsoleTest.java +++ b/src/main/test/ConsoleTest.java @@ -15,9 +15,10 @@ public void testStringInput() { Console c = new Console(); String actual = c.getStringInput(); - Assert.assertEquals( actual, "1"); + Assert.assertEquals(actual, "1"); System.setIn(sysInBackup); } } + diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index 303a066..fd930fa 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -1,6 +1,9 @@ // Test the expected User class from ATM. +import org.testng.Assert; +import org.testng.annotations.Test; + public class UserAccountTest { @Test // tests constructor for user with name & password From fa85d223e8fe200b03db5a6d928b779a9e6b83fd Mon Sep 17 00:00:00 2001 From: Theresa Date: Mon, 15 Mar 2021 00:36:29 -0400 Subject: [PATCH 26/28] Fix a typo --- src/main/java/AccountTrans.java | 2 +- src/main/java/UserManagement.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/AccountTrans.java b/src/main/java/AccountTrans.java index 2b04dac..c6b5665 100644 --- a/src/main/java/AccountTrans.java +++ b/src/main/java/AccountTrans.java @@ -52,7 +52,7 @@ public void transferMoney(BankAccount chosenTransferFromAccount, BankAccount cho Double tranAmount; tranAmount = c.getDoubleInput(); if (tranAmount > chosenTransferFromAccount.getBalance()) { - System.out.println("INSUFFICIENT BALANCE! " + "Please enter a different amount."); + System.out.println("INSUFFICIENT BALANCE! " + "Please enter a new amount."); } else { chosenTransferFromAccount.withdraw(tranAmount); chosenTransferToAccount.deposit(tranAmount); diff --git a/src/main/java/UserManagement.java b/src/main/java/UserManagement.java index 663d758..6a00331 100644 --- a/src/main/java/UserManagement.java +++ b/src/main/java/UserManagement.java @@ -75,7 +75,7 @@ public UserAccount createNewUserAccount() { System.out.println("Congratulations " + this.enteredUserName + "! You have successfully created an account!"); return userAccountsList.get(this.enteredUserName); } else { - System.out.println("Username is already taken. Please select another."); + System.out.println("Username is already taken. Be a bit more original!"); attempts += 1; } } @@ -90,7 +90,7 @@ public void setUpUserAccount() { public void closeAccount() { this.userNamePasswordMap.remove(this.enteredUserName); this.userAccountsList.remove(this.enteredUserName); - System.out.println("Sorry to see you go" + this.enteredUserName + "! Your account is now closed."); + System.out.println("Sorry to see you go " + this.enteredUserName + "! Your account is now closed...Oh, you want your money? LOL"); } } From b533b3829b0d3b71f3cb8de67ab12772847663fe Mon Sep 17 00:00:00 2001 From: Monali Date: Mon, 15 Mar 2021 08:00:33 -0400 Subject: [PATCH 27/28] changes to recipt display --- src/main/java/BankAccount.java | 23 ++++++++++------------- src/main/java/UserManagement.java | 2 +- src/main/test/BankAccountTest.java | 22 +++++++++++----------- src/main/test/UserAccountTest.java | 8 +++----- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index f6e4add..f4d4f01 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -25,9 +25,6 @@ void setType(String accType) { void setBalance(Double accBal) { currentBalance = accBal; } - public String getAccountType() { - return this.accountType; - } public String getAccountType() { return accountType; } @@ -46,16 +43,16 @@ void withdraw(Double wit) { void printTxn(String txnType, Double amt, Double balance){ - System.out.println("|----------------------------------------|"); - System.out.println("| BANK OF ZIP CODE WILMINGTON DE |"); - System.out.println("|----------------------------------------|"); - System.out.println("|" + dateTime() + " "+"|"); - System.out.println("|----------------------------------------|"); - System.out.println("| Transaction Receipt |"); - System.out.println("|" + txnType + " " +"|"); - System.out.println("|" + amt + "" + " "+ "|"); - System.out.println("| Remaining Balance: " + balance + " " + "|"); - System.out.println("|----------------------------------------|"); + System.out.println("|---------------------------------------------------------"); + System.out.println("| BANK OF ZIP CODE WILMINGTON DE "); + System.out.println("|---------------------------------------------------------"); + System.out.println("|" + dateTime() + " "); + System.out.println("|---------------------------------------------------------"); + System.out.println("| Transaction Receipt "); + System.out.println("|" + txnType + " "); + System.out.println("|" + amt + "" + " "); + System.out.println("|Remaining Balance: " + balance + " "); + System.out.println("|---------------------------------------------------------"); } String dateTime(){ diff --git a/src/main/java/UserManagement.java b/src/main/java/UserManagement.java index 663d758..f80ccd4 100644 --- a/src/main/java/UserManagement.java +++ b/src/main/java/UserManagement.java @@ -90,7 +90,7 @@ public void setUpUserAccount() { public void closeAccount() { this.userNamePasswordMap.remove(this.enteredUserName); this.userAccountsList.remove(this.enteredUserName); - System.out.println("Sorry to see you go" + this.enteredUserName + "! Your account is now closed."); + System.out.println("Sorry to see you go " + this.enteredUserName + "! Your account is now closed."); } } diff --git a/src/main/test/BankAccountTest.java b/src/main/test/BankAccountTest.java index a3090bc..5069c85 100644 --- a/src/main/test/BankAccountTest.java +++ b/src/main/test/BankAccountTest.java @@ -5,15 +5,15 @@ // Test the expected Account class from ATM. public class BankAccountTest { - @Test - public void constructorCActTypeTest1() { // tests creation of checking account - type field - // Arrange - Account testAccount = new Account(); - System.out.println(testAccount.checking.type); - String givenCAcctType = "Checking"; - String returnedCAcctType = testAccount.checking.type; - Assert.assertEquals(givenCAcctType, returnedCAcctType); - } +// @Test +// public void constructorCActTypeTest1() { // tests creation of checking account - type field +// // Arrange +// UserAccount testAccount = new UserAccount(); +// System.out.println(testAccount.checking.type); +// String givenCAcctType = "Checking"; +// String returnedCAcctType = testAccount.checking.type; +// Assert.assertEquals(givenCAcctType, returnedCAcctType); +// } @Test @@ -50,7 +50,7 @@ public void setTypeTest () { // tests method to reset account type testBankAccount.setType("Savings"); String returnedAccountType = testBankAccount.getAccountType(); //Assert - Assert.assertEquals(givenAccountType, returnedAccountType); + Assert.assertNotEquals(givenAccountType, returnedAccountType); } @Test @@ -135,4 +135,4 @@ public void dateTimeTest () { // tests return of date and time method Assert.assertEquals(expectedDateTime, returnedDateTime); } -//} +} diff --git a/src/main/test/UserAccountTest.java b/src/main/test/UserAccountTest.java index 3130746..85c449e 100644 --- a/src/main/test/UserAccountTest.java +++ b/src/main/test/UserAccountTest.java @@ -1,13 +1,11 @@ // Test the expected User class from ATM. -<<<<<<< HEAD -//public class UserAccountTest { -/* -======= +import org.junit.Test; +import org.testng.Assert; + public class UserAccountTest { ->>>>>>> 1665f322a3ea91133cbcc6a5bd4d8d916b3abc72 @Test // tests constructor for user with name & password public void testGetConstructorUserNamePWTest() { String expectedUsername = "User01"; From 37cbace0d57e6ec1b2997fcd2813b3bf57b46248 Mon Sep 17 00:00:00 2001 From: Theresa Date: Mon, 15 Mar 2021 08:53:30 -0400 Subject: [PATCH 28/28] Minor changes --- src/main/test/MenuTest.java | 10 ------- src/main/test/TranscationHistTest.java | 36 -------------------------- 2 files changed, 46 deletions(-) delete mode 100644 src/main/test/MenuTest.java delete mode 100644 src/main/test/TranscationHistTest.java diff --git a/src/main/test/MenuTest.java b/src/main/test/MenuTest.java deleted file mode 100644 index ef27336..0000000 --- a/src/main/test/MenuTest.java +++ /dev/null @@ -1,10 +0,0 @@ -import org.testng.annotations.Test; - -public class MenuTest { - - @Test - public void testGetInitialInput(){ - Menu menuTest = new Menu(); - menuTest.printWelcomeMenu(); - } -} diff --git a/src/main/test/TranscationHistTest.java b/src/main/test/TranscationHistTest.java deleted file mode 100644 index 9864e74..0000000 --- a/src/main/test/TranscationHistTest.java +++ /dev/null @@ -1,36 +0,0 @@ -//import org.junit.Test; - -//import static org.junit.Assert.*; - -public class TranscationHistTest { -/* - @Test - public void setType() { - } - - @Test - public void setBalance() { - } - - @Test - public void deposit() { - } - - @Test - public void withdraw() { - } - - @Test - public void getBalance() { - } - - @Test - public void printTxn() { - } - - @Test - public void dateTime() { - } - */ - -} \ No newline at end of file