Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4)We are interested in developing a class names BankAccount. The class includes three instance variables number of type int , owner of type String ,

4)We are interested in developing a class names BankAccount. The class includes three instance variables number of type int, owner of type String, and balance of type double. The constructor method accepts three parameters with the same names and types to initialize the instance variables and thus create a new object of the type BankAccount. Write java code for a fully encapsulated BankAccount class showing the instance variables, the constructor, and three getter methods.

public class BankAccount{

private int number;

private String owner;

private double balance;

public BankAccount (int number, String owner, double balance){

this.number = number;

this.owner = owner;

this.balance = balance;

}

public String get.number{

return number;

}

public String get.owner{

return owner;

}

public String get.balance{

return balance;

}

QUESTION: JAVA

5) Consider the BankAccount class discussed in Question 4. write code for the following tasks. Again, focus on the tasks indicated.You do not have to write a complete program.

a.Declare three variables names account1, account2, and account3 of the BankAccount type, so that each can hold a reference to an object of the BankAccount class.

b.Assume that the two variables named number, and owner of appropriate type have been declared. Also assume that a Scanner object named input is available for reading keyboard input. Prompt the user to enter values for number and owner. Read them. Then, create account1 as an object of the BankAccount type with the user given values for number and owner, and with 0.0 as a balance.

c.Use the appropriate getter method and extract the owner associated with account1 and print it.

d.The Boolean variable minBalance is true if the balance associated with an account is >= 100.00; it is false, otherwise. Use the appropriate getter method, extract the balance associated with account2, determine if the balance is greater than or equal to 100 and assign the Boolean variable minBalance suitably.

e.We are interested in adding a new method named toString to the BankAccount class discussed in Question 4. The method accepts no parameters, and returns a String that simply concatenates the values of the three instance variables, with a tab ( \t ) character in between as separator. Write the complete code for the method.

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions