Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

part 1, 2, 3 and 4. And write in each part. will rate to person who completes al

ID: 3541858 • Letter: P

Question

part 1, 2, 3 and 4. And write in each part. will rate to person who completes all 4.


Classes Senior, Adult, Student, all these classes extend Customer Each has constant data fields SAVINGS_INTEREST, CHECK_INTEREST, CHECK_CHARGE, good! and OVERDRAFT_PENALTY that define these values for customers of that type, and each class implements the corresponding accessors. Class Bank Data field: accounts array (type Account[]). Allocate an array of a reasonable size (e.g., 100), and provide a reallocate method. Methods: addAccount, makeDeposit, makeWithdrawal, getAccount

Explanation / Answer

import java.util.Arrays;



public class Bank {

Account[] account = new Account[100];


public Account[] reallocate(Account[] account){

Account[] acc = new Account[account.length * 2];

for (int i =0; i< account.length; i++ ){

acc[i] = account[i];

}

return acc;

}


public Account addAccount(String name, String address, int age, String telephoneNumber, double balance, String savingsOrChecking, int i){

if (age > 8 && age < 21){

Student student = new Student( name, address,age, telephoneNumber);

if(savingsOrChecking.equalsIgnoreCase("S")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

student.setCustomerNumber(customer.getCustomerNumber()+i);

}

SavingsAccount savings = new SavingsAccount(student, balance);

if (i !=0){

Account acc = new Account(student, balance);

savings.setAccountNumber(acc.getAccountNumber()+i);

}

savings.setAccountType("Savings account");

account[i] = savings;

}

else if(savingsOrChecking.equalsIgnoreCase("C")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

student.setCustomerNumber(customer.getCustomerNumber()+i);

}

CheckingAccount checking = new CheckingAccount(student, balance);

if(i !=0){

Account acc = new Account(student, balance);

checking.setAccountNumber(acc.getAccountNumber()+i);

}

checking.setAccountType("Checking account");

account[i] = checking;

}

}

else if( age > 21 && age < 60){

Adult adult = new Adult( name, address,age, telephoneNumber);

if(savingsOrChecking.equalsIgnoreCase("S")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

adult.setCustomerNumber(customer.getCustomerNumber()+i);

}

SavingsAccount savings = new SavingsAccount(adult, balance);

if (i !=0){

Account acc = new Account(adult, balance);

savings.setAccountNumber(acc.getAccountNumber()+i);

}

savings.setAccountType("Savings account");

account[i] = savings;

}

else if(savingsOrChecking.equalsIgnoreCase("C")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

adult.setCustomerNumber(customer.getCustomerNumber()+i);

}

CheckingAccount checking = new CheckingAccount(adult, balance);

if (i !=0){

Account acc = new Account(adult, balance);

checking.setAccountNumber(acc.getAccountNumber()+i);

}

checking.setAccountType("Checking account");

account[i] = checking;

}

}

else if(age > 60){

Senior senior = new Senior( name, address,age, telephoneNumber);

if(savingsOrChecking.equalsIgnoreCase("S")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

senior.setCustomerNumber(customer.getCustomerNumber()+i);

}

SavingsAccount savings = new SavingsAccount(senior, balance);

if (i !=0){

Account acc = new Account(senior, balance);

savings.setAccountNumber(acc.getAccountNumber()+i);

}

savings.setAccountType("Savings account");

account[i] = savings;

}

else if(savingsOrChecking.equalsIgnoreCase("C")){

if (i !=0){

Customer customer = new Customer( name, address, age, telephoneNumber);

senior.setCustomerNumber(customer.getCustomerNumber()+i);

}

CheckingAccount checking = new CheckingAccount(senior, balance);

if (i !=0){

Account acc = new Account(senior, balance);

checking.setAccountNumber(acc.getAccountNumber()+i);

}

checking.setAccountType("Checking account");

account[i] = checking;

}

}

return account[i];

}


public Account makeDeposit(Account account, double amount){

if (account.getAccountType().charAt(0) =='S'){

SavingsAccount saving = new SavingsAccount(account.getCustomer(), account.getBalance());

saving.deposit(amount);

// If you want you can add interest here by using below line

//saving.addInterest(account.getCustomer());

saving.setAccountType("Savings account");

account = saving;

}

else if (account.getAccountType().charAt(0) =='C'){

CheckingAccount checking = new CheckingAccount(account.getCustomer(), account.getBalance());

checking.deposit(amount);

checking.setAccountType("Checking account");

account = checking;

}

return account;


}

public Account makeWithdrawl(Account account, double amount){

if (account.getAccountType().charAt(0) =='S'){

SavingsAccount saving = new SavingsAccount(account.getCustomer(), account.getBalance());

saving.withdraw(amount);

saving.setAccountType("Savings account");

account = saving;

}

else if (account.getAccountType().charAt(0) =='C'){

CheckingAccount checking = new CheckingAccount(account.getCustomer(), account.getBalance());

checking.withdraw(amount);

checking.setAccountType("Checking account");

account = checking;

}

return account;

}


public void getAccount(Account[] accountFetched){

for(int i = 0; i < accountFetched.length; i++){

if(accountFetched[i]!= null){

System.out.println(accountFetched[i]);

}

}

}

}