Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following BankAccount class. This class has a three- argument constructor method, as well as a method for computing the simple compound interest, and

Consider the following BankAccount class. This class has a three- argument constructor method, as well as a method for computing the simple compound interest, and a couple of accessor methods for returning the bank account owners name and for returning the current balance.

/** BankAccount.java * Trivial class for creating and managing bank accounts */

public class BankAccount { // first, 3 instance variables

 private String name; private double balance; private double interestRate; //yearly rate 
 public BankAccount (String s, double openingBalance, 
 double interest) 
 { name = s; balance = openingBalance; interestRate = interest; 

}

 void compound () { balance += (interestRate / 12) * balance; } 
 public void deposit (double amount) { balance += amount; } 
 public String getName () { return name; } 
 public double getBalance () { return balance; } 

}

Suppose Geek Bank wants to store a lot of bank accounts in a two- dimensional array named geekBank such that accounts[0] stores all the accounts set up in Geek Banks first year in business, accounts[1] will store all the accounts set up in Geek Banks second year in business, and so on. As an example, consider the following declaration and initialization of geekBank:

 BankAccount [] [] geekBank = { 
 { new BankAccount(Fred, 345.00, 0.02), new BankAccount(Mary, 1234.00, 0.02), new BankAccount(Karel, 1.79, 0.025) 

}}

Note that variable geekBank contains a reference to an array. Each element of the array (e.g., geekBank[0], geekBank[1], etc.) contains a reference to an array of BankAccount objects. For example, geekBank[0] is a reference to an array containing 3 BankAccounts. Note that the above statement only initialized geekBank[0] and not the other elements of the array.

QUESTION:

Suppose that geekBank has been completely declared and initialized, not necessarily with the values shown above. In one or two simple, clear, unambiguous English sentences, what does the following loop accomplish?

 double total; int n ; for (int k = 0; k < geekBank.length; k++) 

{ total=0.0; n=0; if (geekBank[k] != null)

 { for (int j = 0; j < geekBank[k].length; j++) 

{ n++;

 total += geekBank[k][j].getBalance(); } 
 System.out.println( total / n ); } 

}

PART B

Write some Java code to print out just the name of the person who has the BankAccount with the smallest balance in all of geekBank. You may assume that all balances have different values, so that theres a single person you will have to locate.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago