Skip to content

ATM #14

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 5 commits into
base: master
Choose a base branch
from
Open

ATM #14

Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions ATM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36" version="7.5.8" editor="www.draw.io" type="github"><diagram id="568dc790-838b-d8c6-b4a6-7d9f0d130896" name="Page-1">3VlfT9swEP80ldgDKHFISx9LgQ1pm5DQtPFoEpN4pHFlu027T79z4jSxk5bSJaUaL9jXO/t8v/tnZ+BNZ6vPHM/jbywkyQA54Wrg3QwQci99B/4pyrqgDF1NiDgNNVNFeKR/iCaWbAsaEmEwSsYSSecmMWBpSgJp0DDnLDPZXlhi7jrHEWkQHgOcNKk/aSjjgnpVHkvRvxAaxeXOrqN/ecbBa8TZItX7DZD3kv8VP89wuZbmFzEOWVYjebcDb8oZk8VotpqSRNm2NFshd7fl143enKRyH4FLrYZcl0cnIVhCTxmXMYtYipPbinqdH4+oBRyYxXKWwNCFIVlR+as2flIsFz7MfhMp1xpmvJAMSNXaXxmba6lCG6XC1vNokmALHmgupD0E84hoLn9jS/BRwmZE8jWwcJJgSZfm6lg7S7Th24g+MAr7Ikc7Niph1m7t++YKhQZaqLI6DGpaVKQci3Zc9JGWOFloZX8IwgdomMABr0O6hGEkc4sVpGduU2CLFr4a6VxtNsl13VcixTNQZ/IoOU2j/cXm2ZtClheaPpbFVJLHOc4BzyDlmH6nbUW4JKvdftP0iFLABBY5Gtmsin63jP64FvljZ7sPGfDvwNpvYD15FpLjQHneJAjAFLJb5FtIQYKFgJQLaqUx4VTtDSeJWSjevey+Gp2YDyDfdIIN4G85wSb7/4sXDFsj/syKuCmEEnKK2acWCJTMvQrr+8pnmnAYVr8WkLIA/Izx8OzT+6O7WOE76Lm39IkBbwf/eM/gd90OcN8UtE5LsHOB/FoVdnuvwaN+Cu7IhObSjrQOKy7qB4f/AQavrFFHgMHrB4bRB+BgtqRFr909NldHC5FRo0SdZ1TGNxxneeq/b+1TzkMyZ4LKiuUuZItnAG7v/jGISfB6jROcBkWRee8C0E2l4oVwcbg0tGOUpaoCUCGZMtkEbpp4ncB04N311iQdJHpinRTau5NCHVRUt5dMfuxL7biXbOGP7WzRV7Jw/V4SuYFCkdRT0KlWa9X0SbMeASIryXeB2kTllRrDXMEhtoPqWuE2tN58LPYrfwc3DIrtD8V93CgSLZlsylLB3pGCU6KuPYvaE8ibIuAlQuY3kZ1yH5wpPevK2ZIn3ZY8OewiTQ6PHaCuEZ7FDaXfCHUvTyVExzbQ3s4YtfkhajuN0tIwtTB9gPYob3DuoNVRDU4nL4b6aeCAR8Pas8Spvx7aVRW1hDHq7QGhCSVNl0Qnv4/Ob9tuJzXTXLVYxuvCMONeEpxxo++/yejpU4Z9pffG/X3LaD5wC7w8Ce+0Xv68lpe/8htP3Tvtrvkg72w++ObX3FOwy6Z53xG1o5aoPcAuMK2+dhbOVX1S9m7/Ag==</diagram></mxfile>
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions src/main/java/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.ArrayList;

abstract class Account {
private double balance = 0;

private ArrayList<String> history = new ArrayList();

public double checkBalance() {
return this.balance;
}

public double addFunds(double n) {
this.balance += n;
history.add("Deposited: $" + n);
return this.balance;
}

public double withDraw(double n) {

if (balance - n >= 0) {
System.out.println("Successful");
history.add("Withdrawn: $" + n);
balance -= n;
} else {
System.out.println("Insufficient funds");
}
return this.balance;
}

public String printHistory() {
String a = "";
for (String x : history) {
System.out.println(x);

a += x;
}
return a;
}
}
5 changes: 5 additions & 0 deletions src/main/java/CheckingAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class CheckingAccount extends Account {


}

223 changes: 223 additions & 0 deletions src/main/java/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@

import java.util.ArrayList;
import java.util.Scanner;

public class Console {


public void Start() {
mainMenu();
}

User currentUser;
int currentAccount;


public void login() {
ArrayList<User> users = UserWarehouse.getList();

Scanner loginInput = new Scanner(System.in);
System.out.println("Please enter Username to login: ");
String userName = loginInput.nextLine();
System.out.println("Please enter a password: ");
String userPassword = loginInput.nextLine();


for (User user : users) {
if (user.getUserName().contains(userName)) {
if (user.getPassword().contains(userPassword)) {
currentUser = user;
accountMenu();
} else {
System.out.println("User does not exist.\n");
mainMenu();
}
} else {
System.out.println("User does not exist.\n");
mainMenu();
}
}
mainMenu();
}

private void mainMenu() {
int userinput;
boolean continueInput;

Scanner input = new Scanner(System.in);
System.out.println("\n-------Welcome-------\n" +
"1: Create Account\n" +
"2: Login\n" +
"3: Exit");
enterInteger();
userinput = 0;
if (input.hasNextInt()) {
userinput = input.nextInt();
} else {
System.out.println("Please try an integer.");
mainMenu();
}
switch (userinput) {
case 1:
UserFactory.createUser();
login();
break;
case 2:
login();
break;
case 3:
exit();
break;
default:
System.out.println("Not a valid selection");
mainMenu();
}
}

public void accountMenu() {
System.out.println("-----------------\n" +
"1: Checking \n" +
"2: Savings\n" +
"3: Investing\n" +
"4: Main Menu");
enterInteger();

Scanner input = new Scanner(System.in);
int userInput;
userInput = 0;
if (input.hasNextInt()) {
userInput = input.nextInt();
} else {
System.out.println("Please try an integer.");
accountMenu();
}
switch (userInput) {
case 1:
currentAccount = 0;
accountActions();
break;
case 2:
currentAccount = 1;
accountActions();
break;
case 3:
currentAccount = 2;
accountActions();
break;
case 4:
mainMenu();
break;
default:
System.out.println("Not a valid selection.");
accountMenu();
}
}

public void accountActions() {
System.out.println("-----------------\n" +
"1: Check Balance\n" +
"2: Add Funds\n" +
"3: Withdraw\n" +
"4: Transaction History\n" +
"5: Transfers\n" +
"6: Back\n");

enterInteger();
Scanner input = new Scanner(System.in);
int userInput;
userInput = 0;
if (input.hasNextInt()) {
userInput = input.nextInt();
} else {
System.out.println("Please try an integer.");
accountActions();
}
switch (userInput) {
case 1:
//check balance
System.out.println("$" + currentUser.accounts.get(currentAccount).checkBalance());
accountActions();
break;
case 2:
//add funds/deposit
System.out.println("Amount to be deposited: ");
double depoFunds = 0;
if (input.hasNextDouble()) {
depoFunds = input.nextDouble();
} else {
System.out.println("Please try an integer.");
accountActions();
}
currentUser.accounts.get(currentAccount).addFunds(depoFunds);
accountActions();
break;
case 3:
//withdraw
System.out.println("Amount to be withdrawn: ");
double withDrawFunds = 0;
if (input.hasNextDouble()) {
withDrawFunds = input.nextDouble();
} else {
System.out.println("Please try an integer.");
accountActions();
}
currentUser.accounts.get(currentAccount).withDraw(withDrawFunds);
accountActions();
break;
case 4:
System.out.println("Transaction history:");
currentUser.accounts.get(currentAccount).printHistory();
accountActions();
break;
case 5:
tranfers();
break;
case 6:
accountMenu();
break;
default:
accountActions();
}
}

private void tranfers() {
int userInput;
int toAccount = 0;
Scanner input = new Scanner(System.in);

System.out.println("-----------------\n" +
"Transfer to: \n" +
"1: Checking\n" +
"2: Savings\n" +
"3: Investing\n");

enterInteger();

if (input.hasNextInt()) {
toAccount = input.nextInt();
} else {
System.out.println("Please try an integer.");
tranfers();
}

double funds = 0;
System.out.println("Amount to transfer: ");
if (input.hasNextDouble()) {
funds = input.nextDouble();
} else {
System.out.println("Please try an integer.");
tranfers();
}
currentUser.accounts.get(currentAccount).withDraw(funds);
currentUser.accounts.get(toAccount - 1).addFunds(funds);
accountActions();
}

private void enterInteger() {
System.out.println("Please enter an integer.");
}

private void exit() {
System.exit(0);
}
}
2 changes: 2 additions & 0 deletions src/main/java/InvestmentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class InvestmentAccount extends Account{
}
15 changes: 10 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* Created by iyasuwatts on 10/17/17.
*/
import org.junit.Test;

public class Main {

public static void main(String[] args){

public static void main(String[] args) {


Console atm = new Console();
atm.Start();


}

}
2 changes: 2 additions & 0 deletions src/main/java/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class SavingsAccount extends Account {
}
99 changes: 99 additions & 0 deletions src/main/java/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import java.util.ArrayList;

public class User {

private int id =0;
private String userName;
private String password;
protected static ArrayList<Account> accounts = new ArrayList<>();

{
//gives three accounts to user upon creation
CheckingAccount checking = new CheckingAccount();
accounts.add(0, checking);
SavingsAccount saving = new SavingsAccount();
accounts.add(1, saving);
InvestmentAccount invest = new InvestmentAccount();
accounts.add(2, invest);
}

public User(String userName, String password) {
this.userName = userName;
this.password = password;
this.id = id;
id++;
}


// public void addCheckingAccount() {
// CheckingAccount checking = new CheckingAccount();
// accounts.add(checking);
// }

public void addSavingsAccount() {
SavingsAccount savings = new SavingsAccount();
accounts.add(1, savings);
}

public void addInvestmentAccount() {
InvestmentAccount invest = new InvestmentAccount();
accounts.add(2, invest);
}

// private void removeCheckingAccount() {
//
// accounts.remove(0);
// }
//
// private void removeSavingsAccount() {
//
// accounts.remove(1);
// }
//
// private void removeInvestmentAccount() {
//
// accounts.remove(2);
// }

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<Account> getAccounts() {
return accounts;
}

public static void setAccounts(ArrayList<Account> accounts) {
User.accounts = accounts;
}

@Override
public String toString() {
return "Username: " + this.getUserName() +
"\nPassword: " + this.getPassword() +
"\nId: " + this.getId();
}


}
Loading