Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this question, you are to (1) create a new class named AccountOwner, (2) modify the Account class, and (3) write a new class named

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

In this question, you are to (1) create a new class named AccountOwner, (2) modify the Account class, and (3) write a new class named AccountOwnerTest for testing the methods of the Account and AccountOwner classes. Create a class named AccountOwner. The AccountOwner class should have the following private data fields: - A private static data field named numOwners of type int, representing the number of AccountOwner objects that have been created. - A private data field named ownerID of type int, representing the ID that uniquely identifies an account owner. - A private data field named name of type String, representing name of an account owner. - A privote data field named accounts which is an Arraylist of Account objects, representing the accounts of an owner. Initialize it to an empty list. In the Account class: - Add a private data field named owner which is an object of the AccountOwner class representing the owner of an account. Add a getter for the owner field. - Change the header of the general constructor to public Account(AccountOwner owner, double initialBalance) and that of the default constructor to public Account(AccountOwner own). In the constructors, add a statement that sets the owner data field to the AccountOwner object passed in as the parameter. Add the following public methods to the AccountOwner class: - A constructor public AccountOwner (String name) that sets the name field to the string name passed as the argument, increments the static numOwners by 1 , and assign the result to the field ownerID. 1 - The getters for the numOwners, ownerlD, name and accounts fields. - The setter for the name field. - A method public void createAccount (double initialBalance) that (1) calls the constructor of the Account class to create a new account with the calling AccountOwner object as the owner, and then (2) add the new account to the accounts data field. - A method public void deposit (Account account, double amount) that deposits the given amount to the given account by calling the deposit() method of the Account object. - Amethod public void withdraw(Account account, double amount) that withdraws the given amount from the given account if the owner is the owner of that account; otherwise the method should print to the console the message "Withdrawal denied: You are not the owner of the account". - A method public double totalBalance() that returns the sum of the balances of all accounts of the owner. - A toString method that begins with the ID and name of the account owner followed by the list of accounts the owner owns, followed by the total balance of all accounts. Keep two decimal places for the total balance. For example, if the account owner's ID and name are 1 and Alice, and has two accounts whose account numbers are 3 and 5 and whose balances are 4000 and 2000 respectively, then the tostring method should return (OwnerID: 1, Name: Alice, Accounts: [(Account Number: 3, Balance: 4060.00), (Account Number: 5, Balance: 2000,00)], Total Balance: 6000.00 ) Create a class named AccountOwnerTest. In the main( ) method of the class: - Create an AccountOwner object named owner1 with name "Alice". Create another AccountOwner object named owner2 with name "Bob". - Write code to simulate the following events: - Owner 1 creates a new account with an initial balance of 1000. - Owner 2 creates a new account with an initial balance of 2000. - Owner 2 creates a new account with an initial balance of 3000. - Owner 1 creates a new account with an initial balance of 4000. - Owner 1 creates a new account with an initial balance of 5000. - Print the AccountOwner objects owner1 and owner2. Your code should print (OwnerID: 1, Name: Alice, Accounts: [(Account Number: 1, Balance: 1000.00), (Account Number: 4, Balance: 4000.00), (Account Number: 5, Balance: 5000.00)], Total Balance: 10000.00) (OwnerID: 2, Name: Bob, Accounts: [(Account Number: 2, Balance: 2000.00), (Account Number: 3, Balance: 3000.00)], Total Balance: 5000.00) - Create a Random object named random, using 2150 as the seed. - Write code to simulate the following events: - Owner 1 deposits a random amount between 0 and 100 to each of her own accounts - Owner 1 deposits a random amount between 0 and 100 to each of Owner 2's accounts - Owner 2 withdraws a random amount between 0 and 100 from each of his own accounts - Owner 2 changes his name to "Brian". - Owner 2 attempts to withdraw 1000 from the first account of Owner 1. This should cause the error message "Withdrawal denied: You are not the owner of the account" to be printed. - Print the AccountOwner objects owner1 and owner2. Your code should print (OwnerID: 1, Name: Alice, Accounts: [(Account Number: 1, Balance: 1090.57), (Account Number: 4, Balance: 4062.90), (Account Number: 5, Balance: 5055.74)], Total Balance: 10209+21 ) (OwnerID: 2, Name: Brian, Accounts: [(Account Number: 2, Balance: 1992.38), (Account Number: 3, Balance: 3040.71)], Total Balance: 5033.09) ubmit your code for the Account, AccountOwner and AccountOwnerTest classes to Vimir

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Choose an appropriate organizational pattern for your speech

Answered: 1 week ago