From 464b75ec9c2f8b16e2ed5ece2d327f409c397a77 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Sat, 28 Feb 2026 23:27:23 -0500 Subject: [PATCH 1/2] App mostly complete. Unable to get deposits and withdrawals to stick to customer account objects. --- .../java/org/codedifferently/BankAccount.java | 117 ++++++++++++++++ .../org/codedifferently/BrokerageAccount.java | 39 ++++++ .../org/codedifferently/CheckingAccount.java | 106 +++++++++++++++ .../java/org/codedifferently/Customer.java | 126 ++++++++++++++++++ src/main/java/org/codedifferently/Main.java | 52 +++++++- .../org/codedifferently/SavingsAccount.java | 47 +++++++ 6 files changed, 480 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/codedifferently/BankAccount.java create mode 100644 src/main/java/org/codedifferently/BrokerageAccount.java create mode 100644 src/main/java/org/codedifferently/CheckingAccount.java create mode 100644 src/main/java/org/codedifferently/Customer.java create mode 100644 src/main/java/org/codedifferently/SavingsAccount.java diff --git a/src/main/java/org/codedifferently/BankAccount.java b/src/main/java/org/codedifferently/BankAccount.java new file mode 100644 index 0000000..3b3d183 --- /dev/null +++ b/src/main/java/org/codedifferently/BankAccount.java @@ -0,0 +1,117 @@ +package org.codedifferently; + +import java.util.Scanner; + +public abstract class BankAccount { + protected String customerFirstName; + protected String customerLastName; + protected int acctNumber; + protected double acctBalance; + protected Customer customer; + protected String acctType; + Scanner sc = new Scanner(System.in); + + public BankAccount() { + } + public BankAccount(Customer person, int acctNumber) { + this.customerFirstName = Customer.firstName; + this.customerLastName = Customer.lastName; + } + + public BankAccount(Customer person, int acctNumber, double acctBalance){ + this.customerFirstName= Customer.firstName; + this.customerLastName= Customer.lastName; + this.acctNumber= person.getAcctNumber(); + this.acctBalance=acctBalance; + } + + public String getAcctType() { + return acctType; + } + + public void setAcctType(String acctType) { + this.acctType = acctType; + } + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String getCustomerFirstName() { + return customerFirstName; + } + + public void setCustomerFirstName(String customerFirstName) { + this.customerFirstName = customerFirstName; + } + + public String getCustomerLastName() { + return customerLastName; + } + + public void setCustomerLastName(String customerLastName) { + this.customerLastName = customerLastName; + } + + public double getAcctBalance() { + return acctBalance; + } + + public void setAcctBalance(double acctBalance) { + this.acctBalance = acctBalance; + } + + public int getAcctNumber() { + return acctNumber; + } + + public void setAcctNumber(int acctNumber) { + this.acctNumber = acctNumber; + } + + public void depositFunds(int acct, String acctType){ + System.out.println("How much money are you depositing?"); + double deposit=sc.nextDouble(); + acctBalance+=deposit; + setAcctBalance(acctBalance); + System.out.println("Your deposit has been processed!"+"\n Your new balance is: "+acctBalance); + } + + public void withdrawFunds(int acctNum, String acctType) { + System.out.println("How much money are you withdrawing?"); + double withdraw=sc.nextDouble(); + if (getAcctBalance() < withdraw) { + System.out.println("Insufficient funds. Please try again"); + } else { + this.acctBalance -= withdraw; + setAcctBalance(this.acctBalance); + } + + } + + public void printSummary(){ + System.out.println("======ACCOUNT SUMMARY======"); + System.out.println("Customer name: "+this.customerFirstName+" "+this.customerLastName); + System.out.println("Account #: "+this.getAcctNumber()); + System.out.println("Account Balance: $"+ this.getAcctBalance()); + } + public void printMonthlyStatement(){ + System.out.println("======MONTHLY STATEMENT======"); + System.out.println("Customer name: "+this.customerFirstName+" "+this.customerLastName); + System.out.println("Account #: "+this.getAcctNumber()); + System.out.println("Account Balance: $"+ this.getAcctBalance()); + } + + + + + + + + + +} diff --git a/src/main/java/org/codedifferently/BrokerageAccount.java b/src/main/java/org/codedifferently/BrokerageAccount.java new file mode 100644 index 0000000..149b3bf --- /dev/null +++ b/src/main/java/org/codedifferently/BrokerageAccount.java @@ -0,0 +1,39 @@ +package org.codedifferently; + +import java.util.Random; + +public class BrokerageAccount extends BankAccount { + Random r = new Random(); + double dailyRateOfReturn = r.nextDouble(-10, 10); + String acctType = "Brokerage Account"; + + public BrokerageAccount(Customer person, int acctNumber, double acctBalance) { + super(person, acctNumber, acctBalance); + } + + public BrokerageAccount() { + + } + + @Override + public void depositFunds(int acct, String acctType) { + super.depositFunds(acct, acctType); + } + + @Override + public void withdrawFunds(int acctNum, String acctType) { + super.withdrawFunds(acctNum, acctType); + } + + @Override + public String getAcctType() { + return acctType; + } + + @Override + public void printSummary() { + + } + +} + diff --git a/src/main/java/org/codedifferently/CheckingAccount.java b/src/main/java/org/codedifferently/CheckingAccount.java new file mode 100644 index 0000000..cf5327b --- /dev/null +++ b/src/main/java/org/codedifferently/CheckingAccount.java @@ -0,0 +1,106 @@ +package org.codedifferently; + +public class CheckingAccount extends BankAccount{ + double overdraftFee= 10; + String acctType= "Checking Account"; + + public CheckingAccount(Customer person, int acctNumber, double acctBalance) { + super(person, acctNumber, acctBalance); + } + + public CheckingAccount() { + + } + + @Override + public void depositFunds(int acct, String acctType) { + super.depositFunds(acct, acctType); + } + + @Override + public void withdrawFunds(int acctNum, String acctType) { + super.withdrawFunds(acctNum, acctType); + } + + @Override + public Customer getCustomer() { + return super.getCustomer(); + } + + @Override + public void setCustomer(Customer customer) { + super.setCustomer(customer); + } + + public CheckingAccount(Customer person, int acctNumber) { + super(person, acctNumber); + } + + @Override + public void setCustomerFirstName(String customerFirstName) { + super.setCustomerFirstName(customerFirstName); + } + + @Override + public String getCustomerLastName() { + return super.getCustomerLastName(); + } + + @Override + public void setCustomerLastName(String customerLastName) { + super.setCustomerLastName(customerLastName); + } + + @Override + public double getAcctBalance() { + return super.getAcctBalance(); + } + + @Override + public void setAcctBalance(double acctBalance) { + super.setAcctBalance(acctBalance); + } + + @Override + public int getAcctNumber() { + return super.getAcctNumber(); + } + + @Override + public void setAcctNumber(int acctNumber) { + super.setAcctNumber(acctNumber); + } + + + @Override + public void printSummary() { + } + + @Override + public void printMonthlyStatement() { + super.printMonthlyStatement(); + } + + @Override + public String getCustomerFirstName() { + return super.getCustomerFirstName(); + } + + public double getOverdraftFee() { + return overdraftFee; + } + + public void setOverdraftFee(double overdraftFee) { + this.overdraftFee = overdraftFee; + } + + @Override + public String getAcctType() { + return acctType; + } + + @Override + public void setAcctType(String acctType) { + this.acctType = acctType; + } +} diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java new file mode 100644 index 0000000..8973a90 --- /dev/null +++ b/src/main/java/org/codedifferently/Customer.java @@ -0,0 +1,126 @@ +package org.codedifferently; + +import java.util.ArrayList; +import java.util.Random; +import java.util.Scanner; + +public class Customer { + static String firstName; + static String lastName; + static Random r = new Random(); + private int acctNumber; + protected double acctBalance; + Scanner sc = new Scanner(System.in); + String[] acctTypes = {"Checking Account","Savings Account","Brokerage Account"}; + + BankAccount bankAccount = new BankAccount() { + }; + CheckingAccount chkAcct = new CheckingAccount(); + BrokerageAccount brkAcct= new BrokerageAccount(); + + ArrayList bankAccounts = new ArrayList<>(); + + Customer(String firstName, String lastName) { + Customer.firstName = firstName; + Customer.lastName = lastName; + acctNumber = r.nextInt(100000000, 999999999); + } + + Customer(String firstName, String lastName, int acctNumber) { + Customer.firstName = firstName; + Customer.lastName = lastName; + this.acctNumber = acctNumber; + } + + public int getAcctNumber() { + return acctNumber; + } + + public void setAcctNumber(int acctNumber) { + this.acctNumber = acctNumber; + } + + public void getCustomerSummary() { + System.out.println("Name: " + firstName + " " + lastName); + System.out.println("Account #: " + firstName + " " + lastName); + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + Customer.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + Customer.firstName = firstName; + } + + public static Customer createNewCustomer() { + Scanner sc = new Scanner(System.in); + System.out.println("Welcome to Freddy's FirstTrust Financial"); + System.out.println("Enter your first name: "); + firstName = sc.nextLine(); + System.out.println("Enter your first name: "); + lastName = sc.nextLine(); + return new Customer(firstName, lastName); + } + + public void printAccountSummaries() { + System.out.println("=====" + getFirstName() + " " + getLastName() + "'s active accounts." + "====="); + for (int i = 0; i < Customer.this.bankAccounts.size(); i++) { + System.out.println("Account number: " + this.bankAccounts.get(i).getAcctNumber()); + System.out.println("Account type: " + this.bankAccounts.get(i).getAcctType()); + System.out.println("Balance: $" + this.bankAccounts.get(i).getAcctBalance()); + System.out.println("========================================"); + System.out.println(" "); + } + } + + public void depositFunds(int acctNumber, String acctType) { + System.out.println("How much money are you depositing?"); + double deposit = sc.nextDouble(); + this.acctBalance += deposit; + bankAccount.setAcctBalance(deposit); + System.out.println("Your deposit has been processed!" + "\n Your new "+ acctType+ "balance is: " + acctBalance); + + } + + public void withdrawFunds(int acctNumber, String acctType) { + System.out.println("How much money are you depositing?"); + double withdraw = sc.nextDouble(); + if (this.acctBalance < withdraw) { + System.out.println("Insufficient funds. Please try again"); + } else { + acctBalance -= withdraw; + } + } + + public String selectAccount() { + boolean valid=false; + String acctType = null; + do { + System.out.println("Which account will you be depositing funds?"); + System.out.println("1. Checking Account\n2. Savings Account\n3. Brokerage Account\n4. Exit"); + int acctSelection = sc.nextInt(); + if (acctSelection > 0 && acctSelection < acctTypes.length) { + acctType = acctTypes[acctSelection-1]; + System.out.println(acctType+" has been selected."); + valid=true; + break; + } else if (acctSelection==4){ + break; + } + else { + System.out.println("Invalid selection. Please try again."); + } + } while (!valid); + return acctType; + } +} + diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..757c23d 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,55 @@ package org.codedifferently; +import java.util.ArrayList; +import java.util.Random; +import java.util.Scanner; + //TIP To Run code, press or // click the icon in the gutter. public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); + Scanner sc = new Scanner(System.in); + + + Customer new1 = Customer.createNewCustomer(); + CheckingAccount chkAcct = new CheckingAccount(new1, new1.getAcctNumber(), 0); + SavingsAccount savAcct = new SavingsAccount(new1, new1.getAcctNumber(), 0); + BrokerageAccount broAcct = new BrokerageAccount(new1, new1.getAcctNumber(), 0); + + //ArrayList bankAccounts = new ArrayList<>(); + new1.bankAccounts.add(chkAcct); + new1.bankAccounts.add(savAcct); + new1.bankAccounts.add(broAcct); + + boolean bankOpen = true; + while (bankOpen) { + System.out.println("=========================================="); + System.out.println("Please review menu and make a selection."); + System.out.println("1. View Accounts."); + System.out.println("2. Deposit Funds."); + System.out.println("3. Withdraw Funds."); + System.out.println("4. View Monthly Statement."); + System.out.println("5. Logout."); + int menuSelection = sc.nextInt(); + switch (menuSelection) { + case 1: + new1.printAccountSummaries(); + continue; + case 2: + String depositAcctType = new1.selectAccount(); + new1.depositFunds(new1.getAcctNumber(), depositAcctType); + break; + case 3: + String withdrawAcctType = new1.selectAccount(); + new1.withdrawFunds(new1.getAcctNumber(), withdrawAcctType); + break; + case 5: + bankOpen=false; + break; + default: + System.out.println("Invalid selection. Please try again."); + } - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); } } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/SavingsAccount.java b/src/main/java/org/codedifferently/SavingsAccount.java new file mode 100644 index 0000000..5961f0e --- /dev/null +++ b/src/main/java/org/codedifferently/SavingsAccount.java @@ -0,0 +1,47 @@ +package org.codedifferently; + +public class SavingsAccount extends BankAccount{ + protected double interestRate; + protected double interestEarned; + String acctType = "Savings Account"; + + public SavingsAccount(Customer person, int acctNumber, double acctBalance) { + super(person, acctNumber, acctBalance); + } + + @Override + public void withdrawFunds(int acctNum, String acctType) { + super.withdrawFunds(acctNum, acctType); + } + + @Override + public void depositFunds(int acct, String acctType) { + super.depositFunds(acct, acctType); + } + + public String getAcctType() { + return acctType; + } + + public void setAcctType(String acctType) { + this.acctType = acctType; + } + + public double getInterestRate() { + return interestRate; + } + + public void setInterestRate(double interestRate) { + this.interestRate = interestRate; + } + + public double getInterestEarned() { + return interestEarned; + } + + public void setInterestEarned(double interestEarned) { + this.interestEarned = interestEarned; + } + + +} From 8a7bbb18a3adda90edf62a870f0f3f681ad3c03a Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Tue, 3 Mar 2026 15:02:40 -0500 Subject: [PATCH 2/2] Deposits and Withdrawals are now sticking to bank account objects. --- .../java/org/codedifferently/BankAccount.java | 5 +- .../java/org/codedifferently/Customer.java | 78 +++++++++++++++---- src/main/java/org/codedifferently/Main.java | 8 +- .../org/codedifferently/SavingsAccount.java | 4 + 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/codedifferently/BankAccount.java b/src/main/java/org/codedifferently/BankAccount.java index 3b3d183..eba8f6e 100644 --- a/src/main/java/org/codedifferently/BankAccount.java +++ b/src/main/java/org/codedifferently/BankAccount.java @@ -13,7 +13,7 @@ public abstract class BankAccount { public BankAccount() { } - public BankAccount(Customer person, int acctNumber) { + public BankAccount(Customer person) { this.customerFirstName = Customer.firstName; this.customerLastName = Customer.lastName; } @@ -25,6 +25,9 @@ public BankAccount(Customer person, int acctNumber, double acctBalance){ this.acctBalance=acctBalance; } + public BankAccount(Customer person, int acctNumber) { + } + public String getAcctType() { return acctType; } diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index 8973a90..93fb446 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -16,6 +16,7 @@ public class Customer { BankAccount bankAccount = new BankAccount() { }; CheckingAccount chkAcct = new CheckingAccount(); + SavingsAccount savAcct = new SavingsAccount(); BrokerageAccount brkAcct= new BrokerageAccount(); ArrayList bankAccounts = new ArrayList<>(); @@ -71,33 +72,76 @@ public static Customer createNewCustomer() { return new Customer(firstName, lastName); } - public void printAccountSummaries() { + public void printAccountSummaries(Customer customer) { System.out.println("=====" + getFirstName() + " " + getLastName() + "'s active accounts." + "====="); - for (int i = 0; i < Customer.this.bankAccounts.size(); i++) { - System.out.println("Account number: " + this.bankAccounts.get(i).getAcctNumber()); - System.out.println("Account type: " + this.bankAccounts.get(i).getAcctType()); - System.out.println("Balance: $" + this.bankAccounts.get(i).getAcctBalance()); + //for (int i = 0; i < Customer.this.bankAccounts.size(); i++) { + System.out.println("Account number: " + customer.getAcctNumber()); + System.out.println("Account type: " + customer.acctTypes[0]); + System.out.println("Balance: $" + customer.chkAcct.getAcctBalance()); System.out.println("========================================"); + System.out.println("Account number: " + customer.getAcctNumber()); + System.out.println("Account type: " + customer.acctTypes[1]); + System.out.println("Balance: $" + customer.savAcct.getAcctBalance()); + System.out.println("========================================"); + System.out.println("Account number: " + customer.getAcctNumber()); + System.out.println("Account type: " + customer.acctTypes[2]); + System.out.println("Balance: $" + customer.brkAcct.getAcctBalance()); + System.out.println("========================================"); + System.out.println(" "); - } + //} } - public void depositFunds(int acctNumber, String acctType) { + public void depositFunds(Customer customer, String acctType) { System.out.println("How much money are you depositing?"); double deposit = sc.nextDouble(); - this.acctBalance += deposit; - bankAccount.setAcctBalance(deposit); - System.out.println("Your deposit has been processed!" + "\n Your new "+ acctType+ "balance is: " + acctBalance); - + switch (acctType) { + case "Checking Account" -> { + double balance = customer.chkAcct.getAcctBalance() + deposit; + customer.chkAcct.setAcctBalance(balance); + System.out.println("Your Checking Account balance is now:"+ balance); + } + case "Savings Account" -> { + double balance = customer.savAcct.getAcctBalance() + deposit; + customer.savAcct.setAcctBalance(balance); + System.out.println("Your Savings Account balance is now:"+ balance); + } + case "Brokerage Account" -> { + double balance = customer.brkAcct.getAcctBalance() + deposit; + customer.brkAcct.setAcctBalance(balance); + System.out.println("Your Brokerage Account balance is now:"+ balance); + } + } } - public void withdrawFunds(int acctNumber, String acctType) { - System.out.println("How much money are you depositing?"); + public void withdrawFunds(Customer customer, String acctType) { + System.out.println("How much money are you withdrawing?"); double withdraw = sc.nextDouble(); - if (this.acctBalance < withdraw) { - System.out.println("Insufficient funds. Please try again"); - } else { - acctBalance -= withdraw; + switch (acctType) { + case "Checking Account" -> { + if (customer.chkAcct.getAcctBalance() < withdraw) { + System.out.println("Insufficient funds. Please try again"); + } else { + double balance = customer.savAcct.getAcctBalance() - withdraw; + customer.chkAcct.setAcctBalance(balance); + } + } + case "Savings Account" -> { + if (customer.savAcct.getAcctBalance() < withdraw) { + System.out.println("Insufficient funds. Please try again"); + } else { + double balance = customer.savAcct.getAcctBalance() - withdraw; + customer.savAcct.setAcctBalance(balance); + } + } + case "Brokerage Account" -> { + if (customer.brkAcct.getAcctBalance() < withdraw) { + System.out.println("Insufficient funds. Please try again"); + } else { + double balance = customer.brkAcct.getAcctBalance() - withdraw; + customer.brkAcct.setAcctBalance(balance); + } + } } } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 757c23d..9246ad8 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -16,7 +16,7 @@ public static void main(String[] args) { SavingsAccount savAcct = new SavingsAccount(new1, new1.getAcctNumber(), 0); BrokerageAccount broAcct = new BrokerageAccount(new1, new1.getAcctNumber(), 0); - //ArrayList bankAccounts = new ArrayList<>(); + ArrayList bankAccounts = new ArrayList<>(); new1.bankAccounts.add(chkAcct); new1.bankAccounts.add(savAcct); new1.bankAccounts.add(broAcct); @@ -33,15 +33,15 @@ public static void main(String[] args) { int menuSelection = sc.nextInt(); switch (menuSelection) { case 1: - new1.printAccountSummaries(); + new1.printAccountSummaries(new1); continue; case 2: String depositAcctType = new1.selectAccount(); - new1.depositFunds(new1.getAcctNumber(), depositAcctType); + new1.depositFunds(new1,depositAcctType); break; case 3: String withdrawAcctType = new1.selectAccount(); - new1.withdrawFunds(new1.getAcctNumber(), withdrawAcctType); + new1.withdrawFunds(new1,withdrawAcctType); break; case 5: bankOpen=false; diff --git a/src/main/java/org/codedifferently/SavingsAccount.java b/src/main/java/org/codedifferently/SavingsAccount.java index 5961f0e..5c85c2e 100644 --- a/src/main/java/org/codedifferently/SavingsAccount.java +++ b/src/main/java/org/codedifferently/SavingsAccount.java @@ -9,6 +9,10 @@ public SavingsAccount(Customer person, int acctNumber, double acctBalance) { super(person, acctNumber, acctBalance); } + public SavingsAccount() { + + } + @Override public void withdrawFunds(int acctNum, String acctType) { super.withdrawFunds(acctNum, acctType);