Skip to content
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

ATM-Machine #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions ATM-Machine-Java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/ATM" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
48 changes: 42 additions & 6 deletions ATM/Account.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Account {
// variables
private int customerNumber;
private int pinNumber;
private double checkingBalance = 0;
private double checkingBalance;
private double savingBalance = 0;
private FileWriter fileWriter;
private PrintWriter printWriter;
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strDate = dateFormat.format(date);

Scanner input = new Scanner(System.in);
DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00");
Expand All @@ -26,7 +37,12 @@ public Account(int customerNumber, int pinNumber, double checkingBalance, double
this.checkingBalance = checkingBalance;
this.savingBalance = savingBalance;
}
//Add the ability to show statement of all your account balances
public String getStatement(){

return "Your checking balance is: "+ getCheckingBalance()+"\n"
+"Your saving balance is: "+ getSavingBalance();
}
public int setCustomerNumber(int customerNumber) {
this.customerNumber = customerNumber;
return customerNumber;
Expand Down Expand Up @@ -83,7 +99,7 @@ public void calcSavingTransfer(double amount) {
checkingBalance = checkingBalance + amount;
}

public void getCheckingWithdrawInput() {
public void getCheckingWithdrawInput(PrintWriter log) {
boolean end = false;
while (!end) {
try {
Expand All @@ -93,6 +109,9 @@ public void getCheckingWithdrawInput() {
if ((checkingBalance - amount) >= 0 && amount >= 0) {
calcCheckingWithdraw(amount);
System.out.println("\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance));
try {
log.println(""+strDate+" Account "+customerNumber+" has withdrawn $" + amount + " from Checking Account.");
} catch (Exception e){}
end = true;
} else {
System.out.println("\nBalance Cannot be Negative.");
Expand All @@ -104,8 +123,9 @@ public void getCheckingWithdrawInput() {
}
}

public void getsavingWithdrawInput() {
public void getsavingWithdrawInput(PrintWriter log) {
boolean end = false;

while (!end) {
try {
System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance));
Expand All @@ -114,6 +134,10 @@ public void getsavingWithdrawInput() {
if ((savingBalance - amount) >= 0 && amount >= 0) {
calcSavingWithdraw(amount);
System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance));
try {
log.println(""+strDate+" Account "+customerNumber+" has withdrawn $" + amount + " from Savings Account.");
} catch (Exception e){}

end = true;
} else {
System.out.println("\nBalance Cannot Be Negative.");
Expand All @@ -125,7 +149,7 @@ public void getsavingWithdrawInput() {
}
}

public void getCheckingDepositInput() {
public void getCheckingDepositInput(PrintWriter log) {
boolean end = false;
while (!end) {
try {
Expand All @@ -135,6 +159,10 @@ public void getCheckingDepositInput() {
if ((checkingBalance + amount) >= 0 && amount >= 0) {
calcCheckingDeposit(amount);
System.out.println("\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance));
try {
log.println(""+strDate+" Account "+customerNumber+" has deposit $" + amount + " from Checking Account.");
} catch (Exception e){}

end = true;
} else {
System.out.println("\nBalance Cannot Be Negative.");
Expand All @@ -146,7 +174,7 @@ public void getCheckingDepositInput() {
}
}

public void getSavingDepositInput() {
public void getSavingDepositInput(PrintWriter log) {
boolean end = false;
while (!end) {
try {
Expand All @@ -157,6 +185,10 @@ public void getSavingDepositInput() {
if ((savingBalance + amount) >= 0 && amount >= 0) {
calcSavingDeposit(amount);
System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance));
try {
log.println(""+strDate+" Account "+customerNumber+" has deposit $" + amount + " from Saving Account.");
} catch (Exception e){}

end = true;
} else {
System.out.println("\nBalance Cannot Be Negative.");
Expand All @@ -168,7 +200,7 @@ public void getSavingDepositInput() {
}
}

public void getTransferInput(String accType) {
public void getTransferInput(String accType,PrintWriter log) {
boolean end = false;
while (!end) {
try {
Expand All @@ -188,6 +220,10 @@ public void getTransferInput(String accType) {
System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance));
System.out.println(
"\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance));
try {
log.println(""+strDate+" Account "+customerNumber+" has transfer $" + amount + " from Checking Account.");
} catch (Exception e){}

end = true;
} else {
System.out.println("\nBalance Cannot Be Negative.");
Expand Down
Loading