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

public class MainBank { /** * @param args the command line arguments */ public s

ID: 3873785 • Letter: P

Question

public class MainBank {
  
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Bank [] banks = {new Bank("Toronto Dominion", 3),
new Bank("Bank of Montreal", 5)};
Bank td = banks[0];
Bank bmo = banks[1];
System.out.println(td);
Account charlie = new Account("Charles", 234, 200.00);
td.add(charlie);
System.out.println(td);
Account dora = new Account("Dora", 456, 300.00);
td.add(dora);
System.out.println("td has account # 456: " +
td.hasAccountNumber(456));
Account ed = new Account("Edward", 456, 400.00);
for(Bank bank : banks) {
if (bank.add(ed)) break;
}
for(Bank bank : banks) {
System.out.println(bank);
}
}

}

output:

Toronto Dominion: 0 of 3 accounts open

Toronto Dominion: 1 of 3 accounts open

(Charles, 234, $200.00)

td has account # 456: true

Toronto Dominion: 2 of 3 accounts open

(Charles, 234, $200.00)

(Dora, 456, $300.00)

Bank of Montreal: 1 of 5 accounts open

(Edward, 456, $400.00)

Explanation / Answer

Account.java

public class Account {

//Declaring instance variables
private String name;
private int accNo;
private double bal;

//Parameterized constructor
public Account(String name, int accNo, double bal) {
super();
this.name = name;
this.accNo = accNo;
this.bal = bal;
}

//getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAccNo() {
return accNo;
}
public void setAccNo(int accNo) {
this.accNo = accNo;
}
public double getBal() {
return bal;
}
public void setBal(double bal) {
this.bal = bal;
}
@Override
public String toString() {
return "(" + name + ", " + accNo + ", " + bal + ")";
}


}

___________________

Bank.java

public class Bank {
private String name;
/**
* An array of Accounts managed by
* this bank.
*/

private Account[] accounts;
private int numAccounts; //number of active accounts

public Bank(String name, int maxNumberAccounts) {
this.name = name;
accounts = new Account[maxNumberAccounts];
numAccounts = 0;

}


/**
* @return the name
*/
public String getName() {
return name; //Fix this
}

/**
* @return the numAccounts
*/
public int getNumAccounts() {
return numAccounts; //Fix this
}


public Account[] getAccounts() {
return accounts; //Fix this
}

/**
* Return true if the Bank already has an account
* with this number; otherwise false.
* @param accountNumber
* @return
*/
public boolean hasAccountNumber(int accountNumber) {

for (int i = 0; i < accounts.length; i++) {
if (accountNumber == accounts[i].getAccNo())
return true;
}


return false; //Fix this
}

/**
* Adds the specified account to the Bank if possible. If the account number
* already exists or the Bank has reached its maximum
* number of accounts, return false and do not add it; otherwise,
* add it and return true.
* @param account
* @return true if successful
*/
public boolean add(Account account) {

for (int i = 0; i < numAccounts; i++) {

if (accounts[i].getAccNo() == account.getAccNo() || (accounts.length == numAccounts))
return false;
}


accounts[numAccounts++] = account;
return true; //Fix this
}

@Override
public String toString() {
//DO NOT MODIFY THIS CODE
String s = getName() + ": " + getNumAccounts() +
" of " + getAccounts().length +
" accounts open";
for (Account account: getAccounts()) {
if (account == null) break;
s += " " + account;
}
return s;
}
}

___________________

package org.students;
public class MainBank {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Bank[] banks = {
new Bank("Toronto Dominion", 3),
new Bank("Bank of Montreal", 5)
};
Bank td = banks[0];
Bank bmo = banks[1];
System.out.println(td);
Account charlie = new Account("Charles", 234, 200.00);
td.add(charlie);
System.out.println(td);
Account dora = new Account("Dora", 456, 300.00);
td.add(dora);
System.out.println("td has account # 456: " +
td.hasAccountNumber(456));
Account ed = new Account("Edward", 456, 400.00);
for (Bank bank: banks) {
if (bank.add(ed)) break;
}
for (Bank bank: banks) {
System.out.println(bank);
}
}
}

_________________

Output:

Toronto Dominion: 0 of 3 accounts open
Toronto Dominion: 1 of 3 accounts open
(Charles, 234, 200.0)
td has account # 456: true
Toronto Dominion: 2 of 3 accounts open
(Charles, 234, 200.0)
(Dora, 456, 300.0)
Bank of Montreal: 1 of 5 accounts open
(Edward, 456, 400.0)


_____________Could you rate me well.Plz .Thank You