Bank Account OOP
Main.java
public class Main {
public static void main(String[] args) {
BankAccount bankAccount = new BankAccount();
bankAccount.setAcct_number("199206104");
bankAccount.setAcct_balance(19900.22);
bankAccount.setCustomer_name("Bob Smith");
bankAccount.setEmail("bob.smith@gmail.com");
bankAccount.setPhone_number("586-490-6444");
System.out.println();
bankAccount.Check(10000.12);
bankAccount.ATM(-2560.19);
bankAccount.ATM(-26800.12);
bankAccount.ATM(1238123.14);
bankAccount.Check(-500000);
}
}
BankAccount.java
import java.text.NumberFormat;
public class BankAccount {
private String acct_number;
private double acct_balance;
private String customer_name;
private String email;
private String phone_number;
public void decribeAcct() {
// format currency
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(acct_balance);
System.out.println("Balance: " + moneyString);
System.out.println("Name: " + this.customer_name);
System.out.println("Phone: " + this.phone_number);
System.out.println("Email: " + this.email);
System.out.println("Account Number: " + this.acct_number);
}
public void Check (double check_amount){
decribeAcct();
NumberFormat acct_bal_format = NumberFormat.getCurrencyInstance();
String Acct_Bal_String = acct_bal_format.format(getAcct_balance());
System.out.println("\nPrevious balance: " + Acct_Bal_String);
setAcct_balance(getAcct_balance() + check_amount) ;
NumberFormat chk_amt_format = NumberFormat.getCurrencyInstance();
String moneyString = chk_amt_format.format(check_amount);
System.out.println("Check Amount: " + moneyString);
decribeAcct();
}
public void ATM ( double atm_amount) {
decribeAcct();
NumberFormat acct_bal_format = NumberFormat.getCurrencyInstance();
String Acct_Bal_String = acct_bal_format.format(getAcct_balance());
System.out.println("\nPrevious balance: " + Acct_Bal_String);
setAcct_balance(getAcct_balance() + atm_amount);
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(atm_amount);
System.out.println("ATM Amount: " + moneyString);
decribeAcct();
}
public String getAcct_number() {
return acct_number;
}
public void setAcct_number(String acct_number) {
this.acct_number = acct_number;
}
public double getAcct_balance() {
return acct_balance;
}
public void setAcct_balance(double acct_balance) {
this.acct_balance = acct_balance;
}
public String getCustomer_name() {
return customer_name;
}
public void setCustomer_name(String customer_name) {
this.customer_name = customer_name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
}
C:\Users\Win10x64i7\.jdks\openjdk-23.0.1\bin\java.exe "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4\lib\idea_rt.jar=62055:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\Win10x64i7\IdeaProjects\BankAccount\out\production\BankAccount Main
Balance: $19,900.22
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Previous balance: $19,900.22
Check Amount: $10,000.12
Balance: $29,900.34
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Balance: $29,900.34
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Previous balance: $29,900.34
ATM Amount: -$2,560.19
Balance: $27,340.15
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Balance: $27,340.15
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Previous balance: $27,340.15
ATM Amount: -$26,800.12
Balance: $540.03
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Balance: $540.03
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Previous balance: $540.03
ATM Amount: $1,238,123.14
Balance: $1,238,663.17
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Balance: $1,238,663.17
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Previous balance: $1,238,663.17
Check Amount: -$500,000.00
Balance: $738,663.17
Name: Bob Smith
Phone: 586-490-6444
Email: bob.smith@gmail.com
Account Number: 199206104
Process finished with exit code 0