Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Two questions are connected to each other. get the balance and account number, and return a String representation. Save this class to your directory and

image text in transcribed

image text in transcribed

Two questions are connected to each other.

get the balance and account number, and return a String representation. Save this class to your directory and modify it as follows: 1. Overload the constructor as follows: - public Account (double initBal, String owner, long number) - initializes the balance, owner, and account number as specified - public Account (double initBal, String owner) - initializes the balance and owner as specified; randomly generates the account number. - public Account (String owner) - initializes the owner as specified; sets the initial balance to 0 and randomly generates the account number. 2. Overload the withdraw method with one that also takes a fee and deducts that fee from the account. Complete in the below test program "TestAccount.jova" so that it will a. Prompt for and read the account holder's name and create an account b. Prompt for and read the initial balance for this account holder and creates a new account c. Prompt for and read the account number for the account holder and create a new account with this account number d. Deposit 100$ into account and prints the new balance e. Withdraw 25$ and prints the new balance import java.util.Scanner; public class TestAccount 1 public static void main(String[] args) \{ String name; double balance; long acctNum; Account acct; Scanner scan = new Scanner (System. in); System.out.println("Enter account holder's first name"); // a.Read the account holder's name and create acct System. out, println( "Account for " + name + ":"); System. out.println(acct); System. out.println(" Enter initial balance"); //b. Read the initial balance for the account holder and create a new account System.out.println("Account for " + name + ":"); System. out.println(acct); //c.Prompt for and read the account number for the account holder and create a new account with this account number System.out.println(" Enter account number"); System.out.println("Account for =+ name + " " "); System. out.println(acct); System.out.print(" Depositing 180 into account, balance is now "); // d. Deposit 100$ into account and prints the new balance System.out.print(" Withdrawing \$25, balance is now "); //e. Withdraw 25$ and print the new balance Q2. Use your "Account.java" class that you implemented in Q1. 1. Add a static method Account consolidate(Account acct1, Account acct2) to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 Two important rules of consolidation: - Only accounts with the same name can be consolidated. The new account gets the same name but a new account number. - Two accounts with the same account number cannot be consolidated. Check these conditions before creating the new account. If either condition fails, do not create the new account; print a useful message and return null. 2. Write a test program "TestAccounts 2 .java" that prompts for and reads in three names and creates an account with an initial balance of $100 for each. Print the three accounts and try to consolidate the second and third into a new account. If consolidation is made, print the consolidated account. Sample Output: Enter name for first account: Jess First account Name: Jess Acct Number: 950541769 Balance: 100.0 Enter name for second account: Rory Second account Name: Rory Acct Number: 90328513 Balance: 100.0 Enter name for third account: Elisa Third account Name: Elisa Acct Number: 1167858083 Balance: 100.0 Trying to consolidate second and third accounts. Sorry, accounts with different names cannot be consolidated. Enter name for first account: Rocky First account Name: Rocky Acct Number: 162523011 Balance: 100.0 Enter name for second account: Jessie Second account Name: Jessie Acct Number: 1657688838 Balance: 100.0 Enter name for third account: Jessie Third account Name: Jessie Acct Number: 1370165226 Balance: 100.0 Trying to consolidate second and third accounts. Result account is Name: Jessie Acct Number: 228883426 Balance: 200.0 **. Upload Account.java, Testaccount.java and TestAccounts2.java files as one zip file to LMS

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

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

What is a cored structure? Under what conditions is it produced?

Answered: 1 week ago

Question

=+ (a) If A(An1) bA(1) for all / and if b Answered: 1 week ago

Answered: 1 week ago

Question

Explain what is meant by the terms unitarism and pluralism.

Answered: 1 week ago