Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Anyone could explain this code step by step?? import java.util.ArrayList; public class Bank { private ArrayList customerList; private ArrayList accountsList; /** Skapar en ny bank

Anyone could explain this code step by step??

import java.util.ArrayList;

public class Bank {

private ArrayList customerList;

private ArrayList accountsList;

/** Skapar en ny bank utan konton. */

public Bank() {

customerList = new ArrayList<>();

accountsList = new ArrayList<>();

}

public int addAccount(String holderName, long idNr) {

// Check that there is a user

Customer checkCustomer = this.findHolder(idNr);

// if findholder return null, it means that there is no customer so it must be

// created

if (checkCustomer == null) {

checkCustomer = new Customer(holderName, idNr);

customerList.add(checkCustomer);

}

BankAccount accountToBeAdded = new BankAccount(checkCustomer);

accountsList.add(accountToBeAdded);

return accountToBeAdded.getAccountNumber();

}

public Customer findHolder(long idNr) {

for (Customer customer : customerList) {

if (customer.getIdNr() == idNr) {

return customer;

}

}

return null;

}

public boolean removeAccount(int number) {

for (int i = 0; i < accountsList.size(); i++) {

// If the account in the list matches the account we are looking for

if (accountsList.get(i).getAccountNumber() == number) {

accountsList.remove(i);

return true;

}

}

return false;

}

public ArrayList getAllAccounts() {

ArrayList sortedBankAccountsList = new ArrayList<>();

for (BankAccount bankAccount : accountsList) {

int pos = 0;

while (pos < sortedBankAccountsList.size() && sortedBankAccountsList.get(pos).getHolder().getName()

.compareToIgnoreCase(bankAccount.getHolder().getName()) < 0) {

pos++;

}

sortedBankAccountsList.add(pos, bankAccount);

}

return sortedBankAccountsList;

}

public BankAccount findByNumber(int accountNumber) {

for (BankAccount bankAccount : accountsList) {

if (bankAccount.getAccountNumber() == accountNumber) {

return bankAccount;

}

}

return null;

}

public ArrayList findAccountsForHolder(long idNr) {

ArrayList tempBankAccount = new ArrayList<>();

for (BankAccount bankAccount : accountsList) {

if (bankAccount.getHolder().getIdNr() == idNr) {

tempBankAccount.add(bankAccount);

}

}

return tempBankAccount;

}

public ArrayList findByPartofName(String namePart) {

ArrayList foundNameCustomerList = new ArrayList<>();

for (BankAccount account : accountsList) {

if (account.getHolder().getName().toLowerCase().contains(namePart.toLowerCase())) {

foundNameCustomerList.add(account.getHolder());

}

}

return foundNameCustomerList;

}

}

thanks in advance, other related class is here>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions