Skip to content

All done finally! #38

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 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
80e9801
Account class complete
Mar 12, 2021
693d338
Account class done
Mar 12, 2021
9e556c3
Merge branch 'master' into abby
Abielf Mar 12, 2021
f33fc18
Merge pull request #1 from jorget93/abby
Abielf Mar 12, 2021
6c5e506
Played with CLI
jorget93 Mar 12, 2021
defe368
Merge pull request #2 from jorget93/miscbranch
jorget93 Mar 13, 2021
44b4d17
added to console
jorget93 Mar 13, 2021
31bd570
stuff
jorget93 Mar 13, 2021
f3a68e9
testin
jorget93 Mar 13, 2021
ebbd54b
Merge pull request #3 from jorget93/myBranch
jorget93 Mar 13, 2021
3514df4
ryans methods
jorget93 Mar 13, 2021
e03bb56
testing again
jorget93 Mar 13, 2021
1456c9f
modded console
jorget93 Mar 13, 2021
7e64ff2
more updates
jorget93 Mar 13, 2021
5da1ca5
added transfer
r-m-hufford Mar 13, 2021
2984303
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 13, 2021
146fc64
greetingTest
jorget93 Mar 13, 2021
1547a76
WOOT atmEngine 1.0 complete
Mar 13, 2021
7da9608
Merge pull request #5 from jorget93/abby
Abielf Mar 13, 2021
a2b4cac
refined console input validation
r-m-hufford Mar 13, 2021
61a58c7
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 13, 2021
b930807
input loops complete and pin started
r-m-hufford Mar 13, 2021
3ba86be
atm version2
Mar 13, 2021
b63d4b1
Merge pull request #6 from jorget93/abby
Abielf Mar 13, 2021
ddff2a7
account tests begun
Mar 13, 2021
8c17751
Merge pull request #7 from jorget93/abby
Abielf Mar 13, 2021
b04e7f4
console updates
r-m-hufford Mar 13, 2021
08939aa
started adding functionality between console and engine
r-m-hufford Mar 14, 2021
d33883c
finished Account tests properly now onto the engine
Mar 14, 2021
c7d32b6
Merge pull request #8 from jorget93/abby
Abielf Mar 14, 2021
e3f11de
cases class added
r-m-hufford Mar 14, 2021
e38b602
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
d0456d1
Merge branch 'master' of /Users/jorge/Projects/IntelliJ/CR-MacroLabs-…
jorget93 Mar 14, 2021
87fe3bd
fixed an error in the engine that prevented any methods from working
Mar 14, 2021
d21e42b
Merge pull request #9 from jorget93/abby
Abielf Mar 14, 2021
835a002
small change. line 38 in console
r-m-hufford Mar 14, 2021
40c17e0
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
cd235ad
removed cases. working from main
r-m-hufford Mar 14, 2021
577784a
AtmEngine up and running
Mar 14, 2021
6f7445d
Merge pull request #10 from jorget93/abby
Abielf Mar 14, 2021
e109611
last push of the night
Mar 14, 2021
2f032a2
Merge pull request #11 from jorget93/abby
Abielf Mar 14, 2021
ec392fa
pin entry line works now
r-m-hufford Mar 14, 2021
71bb6ed
deposit, withdraw and new customer functional.
r-m-hufford Mar 14, 2021
c40ba67
added pin generator
jorget93 Mar 14, 2021
ca03c40
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 14, 2021
bacea44
create new account has been added
r-m-hufford Mar 14, 2021
a602fbf
added comments changed is123 to confirmIsNumber
jorget93 Mar 14, 2021
c61455b
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 14, 2021
281850b
userExists method fixed
Mar 14, 2021
f576ef9
Merge pull request #12 from jorget93/abby
Abielf Mar 14, 2021
6033eee
Fixed isDub & pinGen in BreakCheck
jorget93 Mar 14, 2021
ba0ab72
console changes
r-m-hufford Mar 14, 2021
dacb1a1
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
1cce4d9
Added Go back and Exit in breakcheck
jorget93 Mar 14, 2021
baf6979
Added Go back and Exit in breakcheck
jorget93 Mar 14, 2021
bd68dab
Merge remote-tracking branch 'origin/master'
r-m-hufford Mar 14, 2021
152389c
added exit and go back
r-m-hufford Mar 14, 2021
bfed7f1
same as last
r-m-hufford Mar 14, 2021
4be6f2a
finished transaction history and balance will now return rounded to n…
Mar 14, 2021
374d590
Merge pull request #13 from jorget93/abby
Abielf Mar 14, 2021
b1b7b4b
tests
jorget93 Mar 14, 2021
ff83388
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
3508276
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
48dd7f7
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 14, 2021
6331cf5
tests
jorget93 Mar 14, 2021
8e52691
accepted merge
jorget93 Mar 14, 2021
ed713f7
testing level 8
jorget93 Mar 14, 2021
e06b15e
BreakCheckTests done
jorget93 Mar 14, 2021
827cc15
existing customers, add accounts
r-m-hufford Mar 14, 2021
2e39db1
woking on console tests
jorget93 Mar 14, 2021
2d86bea
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 14, 2021
2ab6093
close, choose and transfer functional
r-m-hufford Mar 15, 2021
3038c70
Added consoleTest
jorget93 Mar 15, 2021
8379e05
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 15, 2021
49854fe
final bug fixes
r-m-hufford Mar 15, 2021
f1ebccd
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 15, 2021
b06a8fb
started ascii art class
jorget93 Mar 15, 2021
7b88744
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 15, 2021
39a0bb4
pin validation
r-m-hufford Mar 15, 2021
11a000e
new method in ATMengine
Mar 15, 2021
e2bbe0d
Merge pull request #14 from jorget93/abby
Abielf Mar 15, 2021
4e17cd3
final fixes
r-m-hufford Mar 15, 2021
b976388
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
jorget93 Mar 15, 2021
dcfa8e6
added ascii art
jorget93 Mar 15, 2021
fa70163
Merge branch 'master' of https://github.com/jorget93/CR-MacroLabs-OOP…
r-m-hufford Mar 15, 2021
01551d0
transfer minor update
r-m-hufford Mar 15, 2021
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
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.12.jar
Binary file not shown.
52 changes: 50 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,54 @@
<groupId>io.zipcoder</groupId>
<artifactId>project-2-atm</artifactId>
<version>1.0-SNAPSHOT</version>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
90 changes: 90 additions & 0 deletions src/main/java/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class Account {

Double balance;
String accountType= "Checking";
//Might use this for something later.
//Maybe an added modifier in case of multiple accounts of same type
String IDnum;
List<Double> transHistory=new ArrayList<>();


//A new instance of account would need starting funds and account type
public Account(Double startingBalance, String typeOfAccount){
if(startingBalance>=0) balance=startingBalance;
else {balance=0.0; System.out.println("Can't open with a negative balance.");}
accountType=typeOfAccount;
}

//the version of the constructor the tests use.
//The console should probably use the other one.
//If this constructor IS used, account defaults to a checking account.
public Account(Double startingBalance){
if(startingBalance>=0) balance=startingBalance;
else {balance=0.0; System.out.println("Can't open with a negative balance.");}
}

public Double getBalance(){
BigDecimal bd = new BigDecimal(balance).setScale(2, RoundingMode.HALF_UP);
balance = bd.doubleValue();
return balance;
}

public String getAccountType(){
return accountType;
}



//Possible area to expand on: perhaps withdrawing works differently pending account type?
//prevents overdrawing. uses return statement for either
//A balance or to be used in the transfer method.
public Double withdraw(Double amount){
if(amount>balance){
System.out.println("Insufficient funds for withdrawal.");
return 0.0;
}else if(amount<0.0){
System.out.println("Cannot withdraw negative amount.");
return 0.0;
}else{balance-=amount;
transHistory.add(-amount);
return amount;}
}

//cannot deposit a negative amount
public void deposit(Double amount){
if (amount>=0.0) {balance+=amount;
transHistory.add(amount);}
if (amount<0.0) System.out.println("You can't deposit what you don't have.");
}



public void transfer(Account gettingMoney, Double amount){

gettingMoney.deposit(this.withdraw(amount));
}

public void showTransactionHistory(){
for(Double i:transHistory){
if(i>0.0){
System.out.println("Deposit : "+i);
}else if(i<0.0){
System.out.println("Withdraw: "+i);}
}
}


//Returns true if the account can be closed. False if not.
public Boolean closeAccount(){
if (balance==0.0){return true;}
else return false;
}



}
60 changes: 60 additions & 0 deletions src/main/java/AsciiArtGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;

public class AsciiArtGenerator {

//:D
public void introMessage() throws InterruptedException {
int width = 100;
int height = 21;

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setFont(new Font("SansSerif", Font.BOLD,20));

Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.drawString("$ ATM $", 5, 18);

for(int y = 0; y< height; y++) {
StringBuilder sb = new StringBuilder();

Thread.sleep(80);

for(int x = 0; x < width; x++) {
sb.append(image.getRGB(x, y) == -16777216 ? "$" : " ");
}
System.out.println(sb);

}
System.out.println("\n");
}
//
// public void intruderMessage() throws InterruptedException {
// int width = 111;
// int height = 21;
//
// BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// Graphics g = image.getGraphics();
// g.setFont(new Font("SansSerif", Font.BOLD,20));
//
// Graphics2D g2 = (Graphics2D) g;
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// g2.drawString("Intruder", 5, 18);
//
// for(int y = 0; y< height; y++) {
// StringBuilder sb = new StringBuilder();
//
// Thread.sleep(80);
//
// for(int x = 0; x < width; x++) {
// sb.append(image.getRGB(x, y) == -16777216 ? "$" : " ");
// }
// System.out.println(sb);
//
// }
// Thread.sleep(200);
// System.out.println("\n");
// }
}
81 changes: 81 additions & 0 deletions src/main/java/AtmEngine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AtmEngine {

Map<String, List<Account>> bank=new HashMap<String, List<Account>>();

//No need for parameters right now, as far as I can tell.
public AtmEngine(){}


public void addNewAccount(String passcode, Account newAccount){
List<Account> tempList = bank.get(passcode);
if(tempList == null) {
tempList = new ArrayList<>();
bank.put(passcode, tempList);
}
tempList.add(newAccount);
}

//Method to close an account
public void closeAccount(String password, int whichOne){
List<Account>currentUserAccounts= bank.get(password);
if(currentUserAccounts.get(whichOne).closeAccount()){
currentUserAccounts.remove(whichOne);
}
}


//Method to show list of available accounts under a passcode
public void printAllAccounts(String password){
List<Account>currentUserAccounts= bank.get(password);
for(int i=0; i<currentUserAccounts.size();i++){
System.out.println("Account #:"+(i+1)+" Type:"+currentUserAccounts.get(i).getAccountType());
System.out.println("Balance-------->"+currentUserAccounts.get(i).getBalance());
}
}


//Method to transfer funds between existing accounts
public void transfer(String password, Integer accountGiving, Integer accountReceiving, Double cash){
List<Account>currentUserAccounts= bank.get(password);
currentUserAccounts.get(accountGiving).transfer(currentUserAccounts.get(accountReceiving),cash);
}


//Method to withdraw from a chosen account
public void withdrawCash(String password, Integer accountUsed, Double cash){
List<Account>currentUserAccounts= bank.get(password);
currentUserAccounts.get(accountUsed).withdraw(cash);
}

//Method to withdraw money from a chosen account.
public void depositCash(String password, Integer accountUsed, Double cash){
List<Account>currentUserAccounts= bank.get(password);
currentUserAccounts.get(accountUsed).deposit(cash);
}

public void showAccountTransactions(String password, Integer accountUsed){
List<Account>currentUserAccounts=bank.get(password);
System.out.println("Transaction history for account #: "+(accountUsed+1));
currentUserAccounts.get(accountUsed).showTransactionHistory();
}

//Method to ensure given password exists in database.
public Boolean userExists(String password){
for (String i : bank.keySet()) {
if(i.equals(password)){return true;}
}
return false;
}

public Integer sizeOfAccountList(String password){
List<Account>currentUserAccounts= bank.get(password);
return currentUserAccounts.size();
}


}
93 changes: 93 additions & 0 deletions src/main/java/BreakCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import javax.swing.*;
import java.sql.SQLOutput;
import java.util.Random;
import java.util.Scanner;

public class BreakCheck {

//Ensures user chooses from options provided
public String confirmIsNumber(){
String newString = "";
boolean redo = true;
while(redo) {
newString = Console.getStringInput("1 - Checking, 2 - Savings, 3 - Investing, 4 - Exit");
switch(newString){
case "1":
redo = false;
return "Checking";
case "2":
redo = false;
return "Savings";
case "3":
redo = false;
return "Investing";
case "4":
System.out.println("Thank you for choosing a real financial institution");
System.exit(0);
default: System.out.println("Please choose from the menu!");
}
}
return null;
}

//Checks that amount entered is a double
public Double isDouble(){

Double result = 0.0;
boolean check = true;
do {
String newString = Console.getStringInput("\r");
try {
result = Double.parseDouble(newString);
check = false;
} catch (NumberFormatException e) {
System.out.println("Please enter valid amount!");
}
} while(check);
return result;
}

public Integer isInteger(){
Integer result = 0;
boolean check = true;
do {
String newString = Console.getStringInput("\r");
try {
result = Integer.parseInt(newString);
check = false;
} catch (NumberFormatException e) {
System.out.println("Please enter valid amount!");
}
} while(check);
return result;
}

//Generates pin for user
public String pinGenerator(){
String newPin = "";
Random randomInt = new Random();
for(int i =8; i > 0; i--) {
newPin += String.valueOf(randomInt.nextInt(10));
}

return newPin;
}

public Integer isPIN(){

Integer result = 0;
boolean check = true;
do {
String newString = Console.getStringInput("\r");
try {
result = Integer.parseInt(newString);
check = false;
} catch (NumberFormatException e) {
System.out.println("Please enter valid PIN");
}
} while(check);
return result;
}


}
Loading