Q2. Write a program that creates a class named BankAccount and contains: • Private attributes: • • ° ° id int), balance double and annual InterestRate (double). These attributes must never take a negative value. beneficiaries String [] ) to store the names of people who may receive the balance of funds when the account owner passes away. count static int ) to keep a record of the number of created objects. Constructors: 。 A 3-argument constructor that creates an account with given annual InterestRate), balance, and list of beneficiaries passed to the constructor as a series of names, e.g. BankAccount(3300, 6.7, "John", "Lili"). The constructor must increment count by 1, and then stores the new count into id. 。 A no-argument constructor that invokes the above 3-arg constructor and sets both balance and annual Interest Rate to 0, and beneficiaries to a new empty (String array of the size 3. Methods: ° Getter methods for all attributes. ° Setter methods for balance, annual Interest Rate ° ° ° ° Setter method for beneficiaries using the header: public void setBeneficiaries(String list) getMonthly Interest() : returns the monthly interest (not the interest rate). Monthly interest is calculated as balance * annualInterestRate / 12. Note: the interest rate is a percentage, e.g. 4.5%. You need to divide it by 100. getNumberOfBenefitieries (): returns the number of beneficiaries on this account. withdraw(double amount): withdraws a specified amount from the account. deposit (double amount): deposits a specified amount to the account. displayInfo(): displays the information of a bank account as shown in the sample run. Write a test program that creates an object of BankAccount with a balance of $33,000, and an annual interest rate of 6.7% with two beneficiaries named: John and Lili. Use withdraw to withdraw $1,500, use deposit to deposit $1,000, then use displayInfo to display the account information. Sample run: Account ID: 1 Current balance: $32500.0 Annual interest rate: 6.700 % Monthly interest rate: 0.558 % Monthly interest: $181.458 2 beneficiaries: [John, Lily]

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question
Q2. Write a program that creates a class named BankAccount and contains:
• Private attributes:
•
•
°
°
id int), balance double and annual InterestRate (double). These attributes must never take a
negative value.
beneficiaries String [] ) to store the names of people who may receive the balance of funds when the
account owner passes away.
count static int ) to keep a record of the number of created objects.
Constructors:
。 A 3-argument constructor that creates an account with given annual InterestRate), balance, and list of
beneficiaries passed to the constructor as a series of names, e.g. BankAccount(3300, 6.7, "John",
"Lili"). The constructor must increment count by 1, and then stores the new count into id.
。 A no-argument constructor that invokes the above 3-arg constructor and sets both balance and
annual Interest Rate to 0, and beneficiaries to a new empty (String array of the size 3.
Methods:
° Getter methods for all attributes.
° Setter methods for balance, annual Interest Rate
°
°
°
°
Setter method for beneficiaries using the header: public void setBeneficiaries(String
list)
getMonthly Interest() : returns the monthly interest (not the interest rate). Monthly interest is calculated
as balance * annualInterestRate / 12. Note: the interest rate is a percentage, e.g. 4.5%. You need to
divide it by 100.
getNumberOfBenefitieries (): returns the number of beneficiaries on this account.
withdraw(double amount): withdraws a specified amount from the account.
deposit (double amount): deposits a specified amount to the account.
displayInfo(): displays the information of a bank account as shown in the sample run.
Write a test program that creates an object of BankAccount with a balance of $33,000, and an annual interest
rate of 6.7% with two beneficiaries named: John and Lili. Use withdraw to withdraw $1,500, use deposit to
deposit $1,000, then use displayInfo to display the account information.
Sample run:
Account ID: 1
Current balance: $32500.0
Annual interest rate: 6.700 %
Monthly interest rate: 0.558 %
Monthly interest: $181.458
2 beneficiaries: [John, Lily]
Transcribed Image Text:Q2. Write a program that creates a class named BankAccount and contains: • Private attributes: • • ° ° id int), balance double and annual InterestRate (double). These attributes must never take a negative value. beneficiaries String [] ) to store the names of people who may receive the balance of funds when the account owner passes away. count static int ) to keep a record of the number of created objects. Constructors: 。 A 3-argument constructor that creates an account with given annual InterestRate), balance, and list of beneficiaries passed to the constructor as a series of names, e.g. BankAccount(3300, 6.7, "John", "Lili"). The constructor must increment count by 1, and then stores the new count into id. 。 A no-argument constructor that invokes the above 3-arg constructor and sets both balance and annual Interest Rate to 0, and beneficiaries to a new empty (String array of the size 3. Methods: ° Getter methods for all attributes. ° Setter methods for balance, annual Interest Rate ° ° ° ° Setter method for beneficiaries using the header: public void setBeneficiaries(String list) getMonthly Interest() : returns the monthly interest (not the interest rate). Monthly interest is calculated as balance * annualInterestRate / 12. Note: the interest rate is a percentage, e.g. 4.5%. You need to divide it by 100. getNumberOfBenefitieries (): returns the number of beneficiaries on this account. withdraw(double amount): withdraws a specified amount from the account. deposit (double amount): deposits a specified amount to the account. displayInfo(): displays the information of a bank account as shown in the sample run. Write a test program that creates an object of BankAccount with a balance of $33,000, and an annual interest rate of 6.7% with two beneficiaries named: John and Lili. Use withdraw to withdraw $1,500, use deposit to deposit $1,000, then use displayInfo to display the account information. Sample run: Account ID: 1 Current balance: $32500.0 Annual interest rate: 6.700 % Monthly interest rate: 0.558 % Monthly interest: $181.458 2 beneficiaries: [John, Lily]
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning