Skip to content

Finished ATM #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
af2e6aa
Stubb language
ryan0 Nov 9, 2019
da4b12a
created accounts and user
Nov 9, 2019
a791c8e
Stub transaction
ryan0 Nov 9, 2019
a0a31bc
Merge branch 'ryan' into dev
ryan0 Nov 9, 2019
7a3b0ef
accounts and tests
Nov 9, 2019
c28b1a1
Merge branch 'ron' into dev
Nov 9, 2019
97d8ac5
savings account
Nov 9, 2019
592a1ac
accounts finished
Nov 9, 2019
d0a7ff4
refactored
Nov 9, 2019
b38ae93
junit
ryan0 Nov 9, 2019
f738c44
pulling for michking
Nov 9, 2019
0e8d74c
AccountMenu added
michkin32 Nov 9, 2019
2ef3f5c
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Nov 9, 2019
906d124
account number
Nov 9, 2019
d643c3c
Merge branch 'ron' into dev
Nov 9, 2019
3ee6a79
console
ryan0 Nov 9, 2019
6c29e85
more additions
Nov 9, 2019
461e4aa
Merge branch 'ron' into dev
Nov 9, 2019
a2a1532
started main menu
Nov 9, 2019
9fc4429
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Nov 9, 2019
e5f83d8
stuff
Nov 9, 2019
93a2e7f
Almost finished account menu
michkin32 Nov 9, 2019
1220fb2
savinf progress on main menu
Nov 9, 2019
80ceb68
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Nov 9, 2019
be59cf3
almost done with main menu
Nov 10, 2019
6af13c3
pulling
Nov 10, 2019
a12e8cc
fixed merge conflict
Nov 10, 2019
3d78a3c
atm updates
Nov 10, 2019
fd6a939
mainmenu update
Nov 10, 2019
5791045
changes
Nov 10, 2019
d21e63d
transfer complete
Nov 10, 2019
987d29c
compilation error fix
Nov 10, 2019
39cbf76
added user repo
Amendoza20 Nov 10, 2019
75a015c
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Amendoza20 Nov 10, 2019
684d162
almost finished login
Amendoza20 Nov 10, 2019
051d4c4
more additions
Nov 10, 2019
a0b987a
changed add account to user
Nov 10, 2019
f6a0e60
user tests finished
Nov 10, 2019
a347365
finished login menu
Amendoza20 Nov 10, 2019
7517be8
User login to push
Amendoza20 Nov 10, 2019
8c6dea7
user repository added
Nov 10, 2019
7a54ab5
removed user depository
Nov 10, 2019
c2a1123
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Amendoza20 Nov 10, 2019
f9b8999
transaction history worked out
Nov 10, 2019
06fd423
oops, working in dev
Nov 10, 2019
3b976f6
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Amendoza20 Nov 10, 2019
e4ffbd0
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Amendoza20 Nov 10, 2019
def9a90
transaction history update
Nov 10, 2019
82a67d1
login page updates
Nov 10, 2019
0d22cbf
somewhat running
Nov 10, 2019
fe1650c
add account fixed
Nov 10, 2019
5c00b82
account creation update
Nov 10, 2019
7947cdb
updates
Nov 10, 2019
efb048a
major updates
Nov 10, 2019
f087314
possibly fixed account menu
michkin32 Nov 10, 2019
774ffc1
update, lots of stuff
Nov 10, 2019
e29df7a
fixed account Menu
michkin32 Nov 10, 2019
e1e2397
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 10, 2019
1fd7ddd
ATM class
Nov 10, 2019
8bee3c1
Merge branch 'ron' into dev
Nov 10, 2019
b404552
Fixed for real accountMenu
michkin32 Nov 10, 2019
37bb4f0
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 10, 2019
49b39c4
ATM now runs program
Nov 10, 2019
0422d10
ya'll ready for some testing?
Nov 10, 2019
dffa096
create other account types
ryan0 Nov 10, 2019
e7ac9aa
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into ryan
ryan0 Nov 10, 2019
1199406
starting account test
michkin32 Nov 10, 2019
3a43d31
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 10, 2019
b4a01c2
account testing done
Nov 10, 2019
50c4159
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 10, 2019
b6abecd
account creation bug fix
ryan0 Nov 11, 2019
2185ef3
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
ryan0 Nov 11, 2019
6cef729
testing
Nov 11, 2019
015e8c1
Merge branch 'ron' into dev
Nov 11, 2019
ede5ecb
doing testing
Nov 11, 2019
347ae88
too much ATM
Nov 11, 2019
7b0972b
added interest
Nov 11, 2019
f504942
makin' in pretty
Nov 11, 2019
4d8e48e
further testing
Nov 11, 2019
14211df
added remove account method
Nov 11, 2019
20ad136
new test
Nov 11, 2019
77572e6
wrapping up for the night
Nov 11, 2019
53cc6e4
did a test for casino
michkin32 Nov 11, 2019
95a8972
done tests for atm
Nov 11, 2019
d1c3e95
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 11, 2019
f816b91
Merge branch 'chris' into dev
Nov 11, 2019
e3d29d9
Merge branch 'dev' of github.com:rond556/CR-MacroLabs-OOP-ATM into dev
michkin32 Nov 11, 2019
2a0dc11
merging
michkin32 Nov 11, 2019
354385a
pusshing
Nov 11, 2019
6ff623e
Merge branch 'dev' of https://github.com/rond556/CR-MacroLabs-OOP-ATM…
Nov 11, 2019
ddbfcc4
added test
Nov 11, 2019
19bb188
pulling
Nov 11, 2019
f7f3ff5
Merge branch 'ron' into dev
Nov 11, 2019
a272b4c
tests
Nov 11, 2019
39d258c
fixed transfer bug
Nov 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Week 2 project: ATM 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
- atmproject.User interface: CLI (Command line interface) Only
- Direct Input
- Numbered options (instead of on-screen buttons)
- ASCII art welcome but not required
Expand All @@ -17,19 +17,19 @@ Tests should demonstrate proper behavior, and proper handling of misuse (eg. att
- Account Actions
- Withdraw from acct
- Deposit to acct
- Transfer across accounts (self)
- Transfer across atmproject.accounts (self)
- Open new account
- Close account (must be empty)
- Print transaction history
- Check balance
- **Challenge:** Transfer to another user's account (but not from)
- Support multiple users
- Users have associated accounts
- Users have associated atmproject.accounts
- Can create new user
- Users are authenticated with a password (generated or provided on user creation)
- Can exit a user and enter another user
- **BONUS** Persistence
- Users and accounts remain persistent
- Users and atmproject.accounts remain persistent
- Opportunity for research


Expand Down
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
<groupId>io.zipcoder</groupId>
<artifactId>project-2-atm</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
177 changes: 177 additions & 0 deletions src/main/java/atmproject/ATM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package atmproject;


import atmproject.accounts.Account;
import atmproject.accounts.InvestmentsAccount;
import atmproject.accounts.SavingsAccount;


public class ATM {
private Console console = new Console(System.in, System.out);
private UserLogin userLogin = new UserLogin();
private User currentUser;
private boolean running = true;
private AccountMenu accountMenu = new AccountMenu();
private Language language = new Language();

public void turnOnATM(){
userLogin.runLoginMenu();
}


public void runMainMenu(User currentUser) {
setCurrentUser(currentUser);
while (running) {
console.println(language.getLang(Language.LangKey.MAINMENU));
Integer userInput = console.getIntegerInput(":");
mainMenuLogic(userInput);
}
}

public void mainMenuLogic(Integer userInput){
switch (userInput) {
case 1:
String transaction = callDeposit();
console.println(transaction);
currentUser.addToHistory(transaction + "\n");
break;
case 2:
transaction = callWithdraw();
console.println(transaction);
currentUser.addToHistory(transaction + "\n");
break;
case 3:
if (currentUser.getAccountList().size() >= 2) {
transaction = callTransfer();
console.println(transaction);
currentUser.addToHistory(transaction + "\n");
} else {
console.println("ERROR: Not enough accounts to transfer money. Please create a new one.");
}
break;
case 4:
console.println(checkBalance());
break;
case 5:
console.println(displayHistory(currentUser));
break;
case 6:
callCreateAccount();
break;
case 7:
callRemoveAccount();
break;
case 8:
returnToLoginMenu();
break;
}
giveInterest();
}

public String callDeposit() {
Account chosenAccount = accountMenu.selectAccount(currentUser);
console.println("How much would you like to deposit?");
Double userInput = console.getDoubleInput("$");
chosenAccount.deposit(userInput);
return String.format("You deposited $%.2f to %s.", userInput, chosenAccount.getAccountName());
}

public String callWithdraw() {
Account chosenAccount = accountMenu.selectAccount(currentUser);
console.println("How much would you like to withdraw?");
Double userInput = console.getDoubleInput("$");
if(userInput <= chosenAccount.getBalance()){
chosenAccount.withdraw(userInput);
return String.format("You withdrew $%.2f from %s.\n", userInput, chosenAccount.getAccountName());
}
return "ERROR: insufficient funds for withdraw.\n";
}

public String callTransfer(){
Account chosenAccount = accountMenu.selectAccount(currentUser);
Account destinationAccount = accountMenu.selectAccount(currentUser);
if(chosenAccount.equals(destinationAccount)){
return "ERROR: Incorrect account entry\n";
} else {
console.println("How much would you like to transfer?");
Double userInput = console.getDoubleInput("$");
if(userInput <= chosenAccount.getBalance()){
chosenAccount.transfer(destinationAccount, userInput);
return String.format("You transferred $%.2f from %s to %s.\n",userInput, chosenAccount.getAccountName(), destinationAccount.getAccountName());
}
return "ERROR: Insufficient funds for transfer.\n";
}
}

public void callCreateAccount(){
console.println("What kind of account would you like to create?\n(1) - Checkings\n(2) - Savings\n(3) - Investments");
Integer typeOfAccount = console.getIntegerInput(":");
switch(typeOfAccount) {
case 1:
Account account = new Account(currentUser, 0.0, "Checkings Account#" + (currentUser.getAccountList().size() + 1));
currentUser.addAccount(account);
break;
case 2:
SavingsAccount savingsAccount = new SavingsAccount(currentUser, 0.0, "Savings Account#" + (currentUser.getAccountList().size() + 1));
currentUser.addAccount(savingsAccount);
break;
case 3:
createInvestmentAccount();
break;

}
}

public void callRemoveAccount() {
Account chosenAccount = accountMenu.selectAccount(currentUser);
if(currentUser.getAccountList().containsValue(chosenAccount)){
currentUser.removeAccount(chosenAccount);
} else {
console.println("ERROR: Chosen account not found.");
}
}

private void createInvestmentAccount() {
console.println("At this bank, you'll need an initial deposit of $15,000 to open an investment account.\nHow " +
"much would you like to deposit?");
Integer input = console.getIntegerInput(":");
if(input > 14999) {
InvestmentsAccount investmentsAccount = new InvestmentsAccount(currentUser, (double)input, "Investment Account#" + (currentUser.getAccountList().size() + 1));
currentUser.addAccount(investmentsAccount);
} else {
console.println("That is not enough of an initial deposit");
}
}

public String checkBalance() {
Account chosenAccount = accountMenu.selectAccount(currentUser);
return String.format("The balance in %s is $%.2f\n", chosenAccount.getAccountName(), chosenAccount.getBalance());
}

public String displayHistory(User currentUser) {
if(currentUser.getTransactionHistory().isEmpty()){
return "You currently have no history.";
}
return currentUser.displayHistory();
}

public void returnToLoginMenu() {
running = false;
}

public void giveInterest(){
for(String name : currentUser.getAccountList().keySet()){
if(currentUser.getAccountList().get(name) instanceof SavingsAccount){
((SavingsAccount) currentUser.getAccountList().get(name)).addInterest();
}
}
}

public void setCurrentUser(User currentUser) {
this.currentUser = currentUser;
}

public boolean isRunning() {
return running;
}
}
54 changes: 54 additions & 0 deletions src/main/java/atmproject/AccountMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package atmproject;

import atmproject.accounts.Account;
import atmproject.accounts.InvestmentsAccount;
import atmproject.accounts.SavingsAccount;

import java.util.LinkedHashMap;
import java.util.Map;

public class AccountMenu {
Account returnedAccount;
Console console = new Console(System.in, System.out);

public Account selectAccount(User user) {
Map<Integer, Account> returnedMap = new LinkedHashMap<>();
returnedAccount = null;
Integer counter = 1;
printAndStoreAccounts(user, returnedMap, counter);
returnedAccount = getUserSelectedAccount(returnedMap, returnedAccount);


return returnedAccount;
}

public Account getUserSelectedAccount(Map<Integer, Account> returnedMap, Account returnedAccount) {
while (returnedAccount == null) {
console.println("\nPlease select an account.");
Integer input = console.getIntegerInput(":");

returnedAccount = getUsersInput(returnedMap, returnedAccount, input);

}
return returnedAccount;
}

public Account getUsersInput(Map<Integer, Account> returnedMap, Account returnedAccount, Integer input) {
if (returnedMap.containsKey(input)) {
returnedAccount = returnedMap.get(input);
} else {
console.println("\nAccount does not exist. Try again: ");
}
return returnedAccount;
}

public void printAndStoreAccounts(User user, Map<Integer, Account> returnedMap, Integer counter) {
console.println("\n");
for (String s : user.accountList.keySet()) {
console.println("(" + counter + ")" + " - " + s);
returnedMap.put(counter, user.accountList.get(s));
counter++;

}
}
}
62 changes: 62 additions & 0 deletions src/main/java/atmproject/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package atmproject;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Console {

private final Scanner input;
private final PrintStream output;

public Console(InputStream in, PrintStream out) {
this.input = new Scanner(in);
this.output = out;
}

public void print(String val, Object... args) {
output.format(val, args);
}

public void newln() {
print("\n");
}

public void println(String val, Object... vals) {
print(val + "\n", vals);
}

public String getStringInput(String prompt, Object... args) {
print(prompt, args);
return input.nextLine();
}

public Double getDoubleInput(String prompt, Object... args) {
String stringInput = getStringInput(prompt, args);
try {
Double doubleInput = Double.parseDouble(stringInput);
return doubleInput;
} catch (NumberFormatException nfe) { // TODO - Eliminate recursive nature
println("[ %s ] is an invalid user input!", stringInput);
println("Try inputting a numeric value!");
return getDoubleInput(prompt, args);
}
}

public Long getLongInput(String prompt, Object... args) {
String stringInput = getStringInput(prompt, args);
try {
Long longInput = Long.parseLong(stringInput);
return longInput;
} catch (NumberFormatException nfe) { // TODO - Eliminate recursive nature
println("[ %s ] is an invalid user input!", stringInput);
println("Try inputting an integer value!");
return getLongInput(prompt, args);
}
}

public Integer getIntegerInput(String prompt, Object... args) {
return getLongInput(prompt, args).intValue();
}

}
26 changes: 26 additions & 0 deletions src/main/java/atmproject/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package atmproject;

import java.util.HashMap;
import java.util.Map;

public class Language {

private Map<LangKey, String> langMap;
public enum LangKey { EXAMPLE1, EXAMPLE2,MAINMENU }

public Language() {

langMap = new HashMap<LangKey, String>();
langMap.put(LangKey.EXAMPLE1, "This is an example");
langMap.put(LangKey.EXAMPLE2, "This is another Example");
langMap.put(LangKey.MAINMENU, "Please select your option:\n" + "(1) - Deposit\n" + "(2) - Withdraw\n" +
"(3) - Transfer\n" + "(4) - Balance\n" + "(5) - View History\n" + "(6) - Create New Account\n" + "(7) - Remove Account\n" +
"(8) - Exit ATM");

}

public String getLang(LangKey key) {
return langMap.get(key);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package atmproject;

/**
* Created by iyasuwatts on 10/17/17.
*/
public class Main {

public static void main(String[] args){

ATM atm = new ATM();
atm.turnOnATM();
}
}
Loading