From 3063f99618f1fe9da1d765bee44cf67ad2862b39 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 27 Oct 2019 14:27:27 -0400 Subject: [PATCH 1/4] Some finished stuff --- pom.xml | 12 ++++++ src/main/java/Account.java | 70 +++++++++++++++++++++++++++++++ src/main/java/AccountActions.java | 2 + src/main/java/Console.java | 35 ++++++++++++++++ src/main/java/CreateAccount.java | 2 + src/main/java/Interface.java | 45 ++++++++++++++++++++ src/main/java/LogIn.java | 2 + src/main/java/Main.java | 9 ---- 8 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Account.java create mode 100644 src/main/java/AccountActions.java create mode 100644 src/main/java/Console.java create mode 100644 src/main/java/CreateAccount.java create mode 100644 src/main/java/Interface.java create mode 100644 src/main/java/LogIn.java delete mode 100644 src/main/java/Main.java diff --git a/pom.xml b/pom.xml index 9901415..ab4fd6a 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 + + 6 + 6 + + + + \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java new file mode 100644 index 0000000..14c6d51 --- /dev/null +++ b/src/main/java/Account.java @@ -0,0 +1,70 @@ +public class Account { + + private String firstName; + private String lastName; + private Double checkingBalance; + private Double savingBalance; + private Double investBalance; + + + public Account(){ + + this.firstName = firstName; + this.lastName = lastName; + this.checkingBalance = 0.00; + this.savingBalance = 0.00; + this.investBalance = 0.00; + } + + public void setFirstName() { + this.firstName = firstName; + } + + public String getFirstName() { + return firstName; + } + + public void setLastName() { + this.lastName = lastName; + } + + public String getLastName() { + return lastName; + } + + public Double getCheckingBalance() { + return checkingBalance; + } + + public void depositChecking(Double deposit) { + this.checkingBalance += deposit; + } + + public void withdrawChecking(Double withdraw) { + this.checkingBalance -= withdraw; + } + + public Double getSavingBalance() { + return savingBalance; + } + + public void depositSaving(Double deposit) { + this.savingBalance += deposit; + } + + public void withdrawSaving(Double withdraw) { + this.savingBalance -= withdraw; + } + + public Double getInvestBalance() { + return investBalance; + } + + public void depositInvest(Double deposit) { + this.investBalance += deposit; + } + + public void withdrawInvest(Double withdraw) { + this.investBalance -= withdraw; + } +} diff --git a/src/main/java/AccountActions.java b/src/main/java/AccountActions.java new file mode 100644 index 0000000..6e19e7f --- /dev/null +++ b/src/main/java/AccountActions.java @@ -0,0 +1,2 @@ +public class AccountActions { +} diff --git a/src/main/java/Console.java b/src/main/java/Console.java new file mode 100644 index 0000000..d20fabc --- /dev/null +++ b/src/main/java/Console.java @@ -0,0 +1,35 @@ +import java.util.Scanner; + +public class Console extends Interface { + + public static void print(String output, Object... args) { + System.out.printf(output, args); + } + + public static void println(String output, Object... args) { + print(output + "\n", args); + } + + public static String getStringInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + String userInput = scanner.nextLine(); + return userInput; + } + + public static Integer getIntegerInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + Integer userInput = Integer.valueOf(scanner.nextLine()); + return userInput; + } + + + public static Double getDoubleInput(String prompt) { + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = Double.valueOf(scanner.nextLine()); + return userInput; + } + +} diff --git a/src/main/java/CreateAccount.java b/src/main/java/CreateAccount.java new file mode 100644 index 0000000..8ef2333 --- /dev/null +++ b/src/main/java/CreateAccount.java @@ -0,0 +1,2 @@ +public class CreateAccount { +} diff --git a/src/main/java/Interface.java b/src/main/java/Interface.java new file mode 100644 index 0000000..94fd7f5 --- /dev/null +++ b/src/main/java/Interface.java @@ -0,0 +1,45 @@ +import sun.rmi.runtime.Log; + +public class Interface { + + Account account = new Account(); + CreateAccount newAccount = new CreateAccount(); + LogIn logIn = new LogIn(); + AccountActions accountActions = new AccountActions(); + + + + + public void atmApp() { + Integer choice; + + do { + + Console.println("Please type one of the following options:\n" + + "1 = Log in to Account.\n" + + "2 = Create new Account.\n" + + "3 = Exit ATM.\n"); + + choice = Console.getIntegerInput("Enter the choice you would like to make.\n"); + + switch (choice) { + + + // LogIn Code + case 1: + break; + + + // Creating new Account Code + case 2: + break; + + + case 3: + Console.println("SHUTTING DOOOWWNNNNNN!!!!!!"); + break; + } + } while (choice != 3); + + } +} diff --git a/src/main/java/LogIn.java b/src/main/java/LogIn.java new file mode 100644 index 0000000..b26bb27 --- /dev/null +++ b/src/main/java/LogIn.java @@ -0,0 +1,2 @@ +public class LogIn { +} 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 c914d183b1205ce6007f76fa64f39c01f27371fd Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 27 Oct 2019 16:20:38 -0400 Subject: [PATCH 2/4] changes in logIn and account --- pom.xml | 8 +++++ src/main/java/Account.java | 44 +++++++++++++++++++++------ src/main/java/AccountActions.java | 2 ++ src/main/java/CreateAccount.java | 1 + src/main/java/Interface.java | 6 ++-- src/main/java/LogIn.java | 24 +++++++++++++++ src/test/LogInTest.java | 49 +++++++++++++++++++++++++++++++ 7 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 src/test/LogInTest.java diff --git a/pom.xml b/pom.xml index ab4fd6a..53d9e98 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,14 @@ + + + junit + junit + 4.12 + test + + \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 14c6d51..9b4cd8c 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -1,7 +1,6 @@ public class Account { - private String firstName; - private String lastName; + String accoutHolder[][] = new String [5][4]; private Double checkingBalance; private Double savingBalance; private Double investBalance; @@ -9,14 +8,41 @@ public class Account { public Account(){ - this.firstName = firstName; - this.lastName = lastName; - this.checkingBalance = 0.00; - this.savingBalance = 0.00; - this.investBalance = 0.00; + //Username and password of client that already exists + accoutHolder[0][0] = "JaneDoe"; + accoutHolder[0][1] = "p123"; + + //Username and password of client that already exists + accoutHolder[1][0] = "JohnS"; + accoutHolder[1][1] = "MK67"; + } - public void setFirstName() { + public Integer getUsername(String username){ + + for (int index = 0; index < 5; index ++){ + + if ( username.equals(accoutHolder[index][0])){ + return 0; + } + } + + return 1; + } + + public Integer getPassword(String password){ + + for (int index = 0; index < 5; index ++){ + + if (password.equals(accoutHolder[index][1])){ + return 0; + } + } + + return 1; + } + + /* public void setFirstName() { this.firstName = firstName; } @@ -66,5 +92,5 @@ public void depositInvest(Double deposit) { public void withdrawInvest(Double withdraw) { this.investBalance -= withdraw; - } + }*/ } diff --git a/src/main/java/AccountActions.java b/src/main/java/AccountActions.java index 6e19e7f..91ee077 100644 --- a/src/main/java/AccountActions.java +++ b/src/main/java/AccountActions.java @@ -1,2 +1,4 @@ public class AccountActions { + + } diff --git a/src/main/java/CreateAccount.java b/src/main/java/CreateAccount.java index 8ef2333..543bf1a 100644 --- a/src/main/java/CreateAccount.java +++ b/src/main/java/CreateAccount.java @@ -1,2 +1,3 @@ public class CreateAccount { + } diff --git a/src/main/java/Interface.java b/src/main/java/Interface.java index 94fd7f5..8921464 100644 --- a/src/main/java/Interface.java +++ b/src/main/java/Interface.java @@ -1,15 +1,13 @@ -import sun.rmi.runtime.Log; + public class Interface { Account account = new Account(); CreateAccount newAccount = new CreateAccount(); - LogIn logIn = new LogIn(); + //LogIn logIn = new LogIn(); AccountActions accountActions = new AccountActions(); - - public void atmApp() { Integer choice; diff --git a/src/main/java/LogIn.java b/src/main/java/LogIn.java index b26bb27..2332e53 100644 --- a/src/main/java/LogIn.java +++ b/src/main/java/LogIn.java @@ -1,2 +1,26 @@ + + public class LogIn { + + public boolean checkUsername(String username){ + Account newAcc = new Account(); + + if(newAcc.getUsername(username) == 0) + return true; + + return false; + } + + + public boolean checkPassword(String password){ + Account newAcc = new Account(); + + if(newAcc.getPassword(password) == 0) + return true; + + return false; + + } + } + diff --git a/src/test/LogInTest.java b/src/test/LogInTest.java new file mode 100644 index 0000000..60ac51f --- /dev/null +++ b/src/test/LogInTest.java @@ -0,0 +1,49 @@ +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class LogInTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCheckUsername() { + + LogIn newLogIn = new LogIn(); + boolean actual = newLogIn.checkUsername("JaneDoe"); + + Assert.assertEquals(true, actual); + } + + @Test + public void testCheckUsername2() { + + LogIn newLogIn = new LogIn(); + boolean actual = newLogIn.checkUsername("Mi"); + + Assert.assertEquals(false, actual); + } + + @Test + public void testCheckPassword(){ + LogIn newLogIn = new LogIn(); + boolean actual = newLogIn.checkPassword("MK67"); + + Assert.assertEquals(true, actual); + } + + @Test + public void testCheckPassword2(){ + LogIn newLogIn = new LogIn(); + boolean actual = newLogIn.checkPassword("556"); + + Assert.assertEquals(false, actual); + } +} From dd609f86ed3890db1e93f6130805b7ac42ba0fa4 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 27 Oct 2019 17:35:30 -0400 Subject: [PATCH 3/4] changes in login and create an account --- src/main/java/Account.java | 40 ++++++++++++++++++++++++++------------ src/main/java/LogIn.java | 22 ++++++++------------- src/test/LogInTest.java | 30 +++++++++++++++++----------- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/main/java/Account.java b/src/main/java/Account.java index 9b4cd8c..f20ba1c 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -1,6 +1,6 @@ public class Account { - String accoutHolder[][] = new String [5][4]; + String accoutHolder[][] = new String [4][10]; private Double checkingBalance; private Double savingBalance; private Double investBalance; @@ -10,36 +10,52 @@ public Account(){ //Username and password of client that already exists accoutHolder[0][0] = "JaneDoe"; - accoutHolder[0][1] = "p123"; + accoutHolder[1][0] = "p123"; //Username and password of client that already exists - accoutHolder[1][0] = "JohnS"; + accoutHolder[0][1] = "JohnS"; accoutHolder[1][1] = "MK67"; } - public Integer getUsername(String username){ + public Integer getUsername(String username){ for (int index = 0; index < 5; index ++){ - if ( username.equals(accoutHolder[index][0])){ - return 0; + if ( username.equals(accoutHolder[0][index])){ + return index; } } - return 1; + return -1; } - public Integer getPassword(String password){ + public boolean getPassword(String password, Integer index){ + + if (password.equals(accoutHolder[1][index])){ + return true; + } + + return false; + } - for (int index = 0; index < 5; index ++){ - if (password.equals(accoutHolder[index][1])){ - return 0; + public String setNewAccount(String username, String password){ + + for (int index = 0; index < 5; index++){ + + if (accoutHolder[0][index] == null){ + + accoutHolder[0][index] = username; + accoutHolder[1][index] = password; + + return "Username: " + accoutHolder[0][index] + " and password: " + accoutHolder[1][index] + + " was created."; } + } - return 1; + return "Can't create account"; } /* public void setFirstName() { diff --git a/src/main/java/LogIn.java b/src/main/java/LogIn.java index 2332e53..7ab40db 100644 --- a/src/main/java/LogIn.java +++ b/src/main/java/LogIn.java @@ -2,25 +2,19 @@ public class LogIn { - public boolean checkUsername(String username){ - Account newAcc = new Account(); - - if(newAcc.getUsername(username) == 0) - return true; - - return false; - } + Integer indexOfUsername; - - public boolean checkPassword(String password){ + public boolean checkUserAndPass(String username, String password){ Account newAcc = new Account(); + this.indexOfUsername = newAcc.getUsername(username); - if(newAcc.getPassword(password) == 0) - return true; - - return false; + if (indexOfUsername != -1){ + return newAcc.getPassword(password, indexOfUsername); + } + return false; } + } diff --git a/src/test/LogInTest.java b/src/test/LogInTest.java index 60ac51f..cb03f61 100644 --- a/src/test/LogInTest.java +++ b/src/test/LogInTest.java @@ -5,19 +5,19 @@ public class LogInTest { - @Before - public void setUp() throws Exception { - } + // @Before + // public void setUp() throws Exception { + // } - @After - public void tearDown() throws Exception { - } + //@After + //public void tearDown() throws Exception { + //} - @Test + @Test public void testCheckUsername() { LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUsername("JaneDoe"); + boolean actual = newLogIn.checkUserAndPass("JaneDoe", "p123"); Assert.assertEquals(true, actual); } @@ -26,7 +26,7 @@ public void testCheckUsername() { public void testCheckUsername2() { LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUsername("Mi"); + boolean actual = newLogIn.checkUserAndPass("mi", "09"); Assert.assertEquals(false, actual); } @@ -34,7 +34,7 @@ public void testCheckUsername2() { @Test public void testCheckPassword(){ LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkPassword("MK67"); + boolean actual = newLogIn.checkUserAndPass("JohnS","MK67"); Assert.assertEquals(true, actual); } @@ -42,8 +42,16 @@ public void testCheckPassword(){ @Test public void testCheckPassword2(){ LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkPassword("556"); + boolean actual = newLogIn.checkUserAndPass("JaneDoe", "Lo"); Assert.assertEquals(false, actual); } + + @Test + public void testNewAccount(){ + Account newAcc = new Account(); + System.out.println(newAcc.setNewAccount("Milo", "9012")); + System.out.println(newAcc.getUsername("Milo")); + } + } From af90050ef24b4e99167ba3f3f97b6aed37620813 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Tue, 29 Oct 2019 10:23:47 -0400 Subject: [PATCH 4/4] User stuff --- src/main/java/Account.java | 65 +--------------------------------- src/main/java/LogIn.java | 20 ----------- src/main/java/User.java | 59 ++++++++++++++++++++++++++++++ src/main/java/UserCreator.java | 38 ++++++++++++++++++++ src/main/java/UserHolder.java | 17 +++++++++ src/test/LogInTest.java | 57 ----------------------------- 6 files changed, 115 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/LogIn.java create mode 100644 src/main/java/User.java create mode 100644 src/main/java/UserCreator.java create mode 100644 src/main/java/UserHolder.java delete mode 100644 src/test/LogInTest.java diff --git a/src/main/java/Account.java b/src/main/java/Account.java index f20ba1c..cb25356 100644 --- a/src/main/java/Account.java +++ b/src/main/java/Account.java @@ -1,6 +1,5 @@ public class Account { - String accoutHolder[][] = new String [4][10]; private Double checkingBalance; private Double savingBalance; private Double investBalance; @@ -8,72 +7,10 @@ public class Account { public Account(){ - //Username and password of client that already exists - accoutHolder[0][0] = "JaneDoe"; - accoutHolder[1][0] = "p123"; - //Username and password of client that already exists - accoutHolder[0][1] = "JohnS"; - accoutHolder[1][1] = "MK67"; - - } - - public Integer getUsername(String username){ - - for (int index = 0; index < 5; index ++){ - - if ( username.equals(accoutHolder[0][index])){ - return index; - } - } - - return -1; - } - - public boolean getPassword(String password, Integer index){ - - if (password.equals(accoutHolder[1][index])){ - return true; - } - - return false; } - public String setNewAccount(String username, String password){ - - for (int index = 0; index < 5; index++){ - - if (accoutHolder[0][index] == null){ - - accoutHolder[0][index] = username; - accoutHolder[1][index] = password; - - return "Username: " + accoutHolder[0][index] + " and password: " + accoutHolder[1][index] + - " was created."; - } - - } - - return "Can't create account"; - } - - /* public void setFirstName() { - this.firstName = firstName; - } - - public String getFirstName() { - return firstName; - } - - public void setLastName() { - this.lastName = lastName; - } - - public String getLastName() { - return lastName; - } - public Double getCheckingBalance() { return checkingBalance; } @@ -108,5 +45,5 @@ public void depositInvest(Double deposit) { public void withdrawInvest(Double withdraw) { this.investBalance -= withdraw; - }*/ + } } diff --git a/src/main/java/LogIn.java b/src/main/java/LogIn.java deleted file mode 100644 index 7ab40db..0000000 --- a/src/main/java/LogIn.java +++ /dev/null @@ -1,20 +0,0 @@ - - -public class LogIn { - - Integer indexOfUsername; - - public boolean checkUserAndPass(String username, String password){ - Account newAcc = new Account(); - this.indexOfUsername = newAcc.getUsername(username); - - if (indexOfUsername != -1){ - return newAcc.getPassword(password, indexOfUsername); - } - - return false; - } - - -} - diff --git a/src/main/java/User.java b/src/main/java/User.java new file mode 100644 index 0000000..9337c6b --- /dev/null +++ b/src/main/java/User.java @@ -0,0 +1,59 @@ +import java.util.ArrayList; + +public class User { + + private int id = 0; + private String username; + private String password; + protected static ArrayList accounts = new ArrayList(); + + + + public User(String username, String password) { + this.username = username; + this.password = password; + this.id = id; + id++; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUserName() { + return username; + } + + public void setUserName(String userName) { + this.username = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + + } + + public static ArrayList getAccounts() { + return accounts; + } + + public static void setAccounts(ArrayList accounts) { + User.accounts = accounts; + } + + @Override + public String toString() { + return "Username: " + this.getUserName() + + "\nPassword: " + this.getPassword() + + "\nId: " + this.getId(); + } + +} diff --git a/src/main/java/UserCreator.java b/src/main/java/UserCreator.java new file mode 100644 index 0000000..0bcf2fc --- /dev/null +++ b/src/main/java/UserCreator.java @@ -0,0 +1,38 @@ +import java.util.Scanner; + +public class UserCreator { + + public UserCreator(){ + + } + + public static User createUser() { + + String username = setUsername(); + String password = setPassword(); + + + User newUser = new User(username, password); + UserHolder.addUser(newUser); + + return newUser; + } + + public static String setUsername() { + String username; + Scanner input = new Scanner(System.in); + System.out.println("Create a Username: "); + username = input.next(); + return username; + + } + + public static String setPassword() { + String password; + Scanner input = new Scanner(System.in); + System.out.println("Create a password: "); + password = input.nextLine(); + return password; + } + +} diff --git a/src/main/java/UserHolder.java b/src/main/java/UserHolder.java new file mode 100644 index 0000000..43ce8e4 --- /dev/null +++ b/src/main/java/UserHolder.java @@ -0,0 +1,17 @@ +import java.util.ArrayList; + +public class UserHolder { + + static final ArrayList users = new ArrayList(); + + public static void addUser(User newUser) { + System.out.println("Your username and password is created\n"); + users.add(newUser); + + } + + + public static ArrayList getList() { + return users; + } +} diff --git a/src/test/LogInTest.java b/src/test/LogInTest.java deleted file mode 100644 index cb03f61..0000000 --- a/src/test/LogInTest.java +++ /dev/null @@ -1,57 +0,0 @@ -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class LogInTest { - - // @Before - // public void setUp() throws Exception { - // } - - //@After - //public void tearDown() throws Exception { - //} - - @Test - public void testCheckUsername() { - - LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUserAndPass("JaneDoe", "p123"); - - Assert.assertEquals(true, actual); - } - - @Test - public void testCheckUsername2() { - - LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUserAndPass("mi", "09"); - - Assert.assertEquals(false, actual); - } - - @Test - public void testCheckPassword(){ - LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUserAndPass("JohnS","MK67"); - - Assert.assertEquals(true, actual); - } - - @Test - public void testCheckPassword2(){ - LogIn newLogIn = new LogIn(); - boolean actual = newLogIn.checkUserAndPass("JaneDoe", "Lo"); - - Assert.assertEquals(false, actual); - } - - @Test - public void testNewAccount(){ - Account newAcc = new Account(); - System.out.println(newAcc.setNewAccount("Milo", "9012")); - System.out.println(newAcc.getUsername("Milo")); - } - -}