diff --git a/src/main/java/org/codedifferently/BankAccount.java b/src/main/java/org/codedifferently/BankAccount.java new file mode 100644 index 0000000..eba8f6e --- /dev/null +++ b/src/main/java/org/codedifferently/BankAccount.java @@ -0,0 +1,120 @@ +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) { + 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 BankAccount(Customer person, int acctNumber) { + } + + 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..93fb446 --- /dev/null +++ b/src/main/java/org/codedifferently/Customer.java @@ -0,0 +1,170 @@ +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(); + SavingsAccount savAcct = new SavingsAccount(); + 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(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: " + 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(Customer customer, String acctType) { + System.out.println("How much money are you depositing?"); + double deposit = sc.nextDouble(); + 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(Customer customer, String acctType) { + System.out.println("How much money are you withdrawing?"); + double withdraw = sc.nextDouble(); + 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); + } + } + } + } + + 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..9246ad8 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(new1); + continue; + case 2: + String depositAcctType = new1.selectAccount(); + new1.depositFunds(new1,depositAcctType); + break; + case 3: + String withdrawAcctType = new1.selectAccount(); + new1.withdrawFunds(new1,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..5c85c2e --- /dev/null +++ b/src/main/java/org/codedifferently/SavingsAccount.java @@ -0,0 +1,51 @@ +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); + } + + public SavingsAccount() { + + } + + @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; + } + + +}