Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Continue working on the Account class. Add one more instance variable called acctNum, which is used to save accout number. Overload the contructor with three

  1. Continue working on the Account class. Add one more instance variable called acctNum, which is used to save accout number.

  1. Overload the contructor with three parameters, one for each instance variable.

  1. Rewrite the deposit method with += operator.

  1. Add the method toString, which should return a string containing the name, account number, and balance of the account. The method header is provided below.

public String toString()

  1. Add method chargeFee, which should deduct a service fee $10.00 from the account instance variable balance.

  1. Add method changeName which takes a string as a parameter (newName) and changes the name on the account to be that string.

name = newName;

  1. Finally, use the provided file ManageAccounts.java as a skeleton of the testing program. Complete the code in this file to test your Account class.

Account.java:

// ******************************************************* // Account.java // // A bank account class with methods to deposit to, withdraw from, // change the name on, charge a fee to, and print a summary of the account. // ******************************************************* public class Account { // Your code here: declare an instance variable called balance // Your code here: declare an instance variable called name; // Your code here: declare an instance variable called acctNum; // --------------------------------------------- //Constructor -- initializes balance, owner, and account number // -------------------------------------------- public Account(double initBal, String owner, int number) { // Your code here: use the parameters to initialize instance variables } // -------------------------------------------- // Checks to see if balance is sufficient for withdrawal. // If so, decrements balance by amount; if not, prints message. // -------------------------------------------- public void withdraw(double amount) { if (balance >= amount) balance -= amount; else System.out.println("Insufficient funds"); } // -------------------------------------------- // Adds deposit amount to balance. // -------------------------------------------- public void deposit(double amount) { balance += amount; } // -------------------------------------------- // Returns balance. // -------------------------------------------- public double getBalance() { return balance; } // -------------------------------------------- // Returns a string containing the name, account number, and balance. // -------------------------------------------- public String toString() { // YOUR CODE HERE; } // -------------------------------------------- // Deducts $10 service fee // // -------------------------------------------- public void chargeFee() { // YOUR CODE HERE; } // -------------------------------------------- // Changes the name on the account // -------------------------------------------- public void changeName(String newName) { // YOUR CODE HERE; } }

ManageAccounts.java:

// ************************************************************ // ManageAccounts.java // // Use Account class to create and manage Sally and Joe's // bank accounts // ************************************************************ public class ManageAccounts { public static void main(String[] args) { Account acct1, acct2; //create account1 for Sally with $1000 acct1 = new Account(1000, "Sally", 1111); //create account2 for Joe with $500 acct2 = new Account(500,"Joe",1112); //deposit $100 to Joe's account by calling certain method acct2.deposit(100); //print Joe's new balance (use getBalance()) System.out.println(acct2.getBalance()); //your code here: withdraw $50 from Sally's account //your code here: print Sally's new balance (use getBalance()) //your code here: charge fees to both accounts //your code here: change the name on Joe's account to Joseph //your code here: print both acct1 and acct2 } }

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

3. Identify challenges to good listening and their remedies

Answered: 1 week ago

Question

4. Identify ethical factors in the listening process

Answered: 1 week ago