Modify class account to provide a method

Assignment Help Business Management
Reference no: EM132140353

Problem 1. Modify class Account to provide a method called debit that withdraws money from an Account. Ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the method should print a message indicating "Debit amount exceeded account balance." class AccountTest to test method debit. You can find the Account class template on Canvas.

Note:  Refer to "CSC110_Chp3-Classes-v3.ppt" Slides 64-70 to see a sample code

Below is the Sample Output:

account1 balance: $50.00

account2 balance: $0.00

Enter withdrawal amount for account1: 25.67

subtracting 25.67 from account1 balance

account1 balance: $24.33

account2 balance: $0.00

Enter withdrawal amount for account2: 10.00

subtracting 10.00 from account2 balance

Debit amount exceeded account balance.

account1 balance: $24.33

account2 balance: $0.00

The code for the account class you need to modify can be found below. You will need to driver class in order to create objects of the class and test them!

Note:  Refer to "CSC110_Chp3-Classes-v3.ppt" Slides 64-70 to see a sample code

/**

* Lab 5: Account.java

* Last Edited 10/18/2016 by Author Name

* Compilation: javac Account.java

*

* Account class with a constructor to initialize

* instance variable balance.

*

* -- Methods --

* Constructor:

*  public Account(double initialBalance)

*

*  constructs a Account object and sets balance of

*  the account to initialBalance

*

*  sample use:

*  Account myAccount = new Account(500.0);

*  will account object with balance 500;

*

* credit method:

*  public void credit( double amount);

*  

*  will increase the balance of the account by amount

*

* getBalance method:

*  public double getBalance();

*   

*  returns the balance of the account as a double

*/

 

public class Account

{  

  private double balance; // instance variable that stores the balance

 

  // constructor 

  public Account( double initialBalance )

  {

     // validate that initialBalance is greater than 0.0;

     // if it is not, balance is initialized to the default value 0.0

     if ( initialBalance > 0.0 )

        balance = initialBalance;

  } // end Account constructor

 

  // credit (add) an amount to the account

  public void credit( double amount )

  {     

     balance = balance + amount; // add amount to balance

  } // end method credit

 

  /* write code to declare method debit */

 

  // return the account balance

  public double getBalance()

  {

     return balance; // gives the value of balance to the calling method

  } // end method getBalance

} // end class Account

Reference no: EM132140353

Questions Cloud

Address in multiple rows using oracle sql : How would I concatenate an address in multiple rows using Oracle SQL?
Why do you suppose the bb8 just seems to sell itself : If you were president of Galaxy Incorporated, what strategy would you follow from this point forward to improve the company's overall profits?
Should juvenile offenders be treated differently from adults : Create and analyze a 1-2-page simulated case study of an adolescent with developmental challenges. Then, create a 5-7-page intervention plan.
Describe the technologies or techniques : Describe the technologies or techniques, and explain how they would provide a compelling experience for the audience.
Modify class account to provide a method : Modify class Account to provide a method called debit that withdraws money from an Account. Ensure that the debit amount does not exceed the Account's balance
Who would you consider the hero in this story : What insights did you gain from this reading? As we examine this week's objectives, who would you consider the hero in this story?
Correlation between rainfall and average yield : STAT102 - BUSINESS DATA ANALYSIS - Is there a correlation between rainfall and average yield to suggest a linear relationship? Please explain the correlation
Biggest benefits to creating a program : In what scenario would it be appropriate to utilize a stack over a recursive implementation? Please provide an example to illustrate your points.
Display the delivery method : Use a sentinel value to end the program. Test the program using the following part numbers: 7MP6, 3fs5, 8ko89, and 1234MS.

Reviews

Write a Review

Business Management Questions & Answers

  Caselet on michael porter’s value chain management

The assignment in management is a two part assignment dealing 1.Theory of function of management. 2. Operations and Controlling.

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. Due to increase in the preference for light beer drinkers, Chris Prangel wants to introduce light beer version in Mountain Man. An analysis into the la..

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. An analysis into the launch of Mountain Man Light over the present Mountain Man Lager.

  Analysis of the case using the doing ethics technique

Analysis of the case using the Doing Ethics Technique (DET). Analysis of the ethical issue(s) from the perspective of an ICT professional, using the ACS Code of  Conduct and properly relating clauses from the ACS Code of Conduct to the ethical issue.

  Affiliations and partnerships

Affiliations and partnerships are frequently used to reach a larger local audience? Which options stand to avail for the Hotel manager and what problems do these pose.

  Innovation-friendly regulations

What influence (if any) can organizations exercise to encourage ‘innovation-friendly' regulations?

  Effect of regional and corporate cultural issues

Present your findings as a group powerpoint with an audio file. In addition individually write up your own conclusions as to the effects of regional cultural issues on the corporate organisational culture of this multinational company as it conducts ..

  Structure of business plan

This assignment shows a structure of business plan. The task is to write a business plane about a Diet Shop.

  Identify the purposes of different types of organisations

Identify the purposes of different types of organisations.

  Entrepreneur case study for analysis

Entrepreneur Case Study for Analysis. Analyze Robin Wolaner's suitability to be an entrepreneur

  Forecasting and business analysis

This problem requires you to apply your cross-sectional analysis skills to a real cross-sectional data set with the goal of answering a specific research question.

  Educational instructional leadership

Prepare a major handout on the key principles of instructional leadership

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd