Question
Java Bank Example : We already have a withdraw and deposit functions on account but what I am looking for is to implement a customer
Java Bank Example : We already have a withdraw and deposit functions on account but what I am looking for is to implement a customer depositing and withdrawing from their account. Basically you will be using the withdraw and deposit functions. Also to make the homework easier you can set the MAX_ACCOUNTS and MAX_CUSTOMERS to 1 for now package bankexample; import java.util.UUID; public class Account { private final UUID id; private Double balance; private Double interestRate; private AccountType accountType; private Customer customer; public Account(AccountType accountType, Double interestRate) { this.balance = 0.0; this.interestRate = interestRate; this.accountType = accountType; this.id = UUID.randomUUID(); } public double getBalance() { return balance; } public UUID getId() { return id; } public double getInterestRate() { return interestRate; } public void setInterestRate(double interestRate) { this.interestRate = interestRate; } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public void deposit(double cash) { if(cash > 0) { this.balance += cash; } } public Boolean withdraw(double cash) { Boolean success = false; if(this.balance >= cash && cash > 0 ) { this.balance -= cash; success = true; } return success; } public void calculateInterest() { this.balance += this.balance * this.interestRate; } } package bankexample; public enum AccountType { Savings, Checking, CreditCard } package bankexample; public class Bank { public static void main(String[] args) { Bank bankExample = new Bank(); bankExample.start(); } public final static Integer MAX_ACCOUNTS = 2; public final static Integer MAX_CUSTOMERS = 2; private final static Double INTEREST_RATE = 0.02; private Customer[] customers; private Account[] accounts; public Bank() { this.accounts = new Account[MAX_CUSTOMERS * MAX_ACCOUNTS]; this.customers = new Customer[MAX_CUSTOMERS]; } public void start() { createAllCustomers(); } private void createAccountsForAllCustomers() { for(int i = 0; i < this.customers.length; i++) { for(int k = 0; k < MAX_ACCOUNTS; k++) { Account account = new Account( AccountType.Checking, INTEREST_RATE ); account.setCustomer(this.customers[i]); this.accounts[2 * i + k] = account; } } } private void createAllCustomers() { for(int i = 0; i < this.customers.length; i++) { Customer customer = new Customer( "FN " + i, "LN " + i, "FN_LN " + i + "at mail . com", "password" ); this.customers[i] = customer; } } public void outputAllCustomers() { for(int i = 0; i < this.customers.length; i++) { System.out.println(this.customers[i]); } } } package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName; public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return this.firstName + " " + this.lastName; } } package bankexample; public class Vault { private Double cash; public Vault() { this.cash = 0.0; } public Double getCash() { return cash; } public void addCash(Double cash) { if(cash > 0) { this.cash += cash; } } public Boolean removeCash(Double cash) { Boolean success = false; if(this.cash >= cash) { this.cash -= cash; success = true; } return success; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started