Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

must be in java: For this problem, I want us to practice creating an array of object. We must first have a class to add

must be in java:

For this problem, I want us to practice creating an array of object. We must first have a class to add to our array and for this problem, we are going to use what we already have, BankAccount.

Open the BankAccount class, you can use the basic one.

Create a BankAccountArrayTester class.

Create an array of type BankAccount that holds 10 BankAccount object. You create this by typing: BankAccount[] bankArray=new BankAccount[10].

Create a loop.

Inside the loop create a BankAccount. Put a different balance in each.

Add the BankAccount object to your array. Simply add the variable name to the array.

Once you have created the array we need to print it. Create another loop.

Inside the loop, we will print the balance for each element of the BankAccount array. Because it is an object, you cant do this directly. You must use the getBalance method. Your code should look something like: System.out.println(Balance is: + bankArray[i].getBalance());

BankAccount class :

{ private double balance; public BankAccount() {

balance = 0;

}

public BankAccount(double initialBalance) { balance = initialBalance; }

public void deposit(double amount) { balance= balance + amount; }

public void withdraw(double amount) { balance = balance - amount; }

public double getBalance() { return balance; } }

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

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

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

8. Provide recommendations for how to manage knowledge.

Answered: 1 week ago