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

  Develope ethical and authentic leadership behaviors

Developing Ethical and Authentic Leadership Behaviors- Describe the terminal and/or instrumental values proposed by Rokeach on pages 26-27 of the Gamble and Gamble text that may have guided the leader's decision making.

  Explain how big a factor do you think composition workforce

Explain how big a factor do you think composition of the workforce is in the likelihood of producing a CEO?

  Utilization of health care services

Analyze the factors that drive people to seek health care and determine which have the biggest impact on you. Provide specific examples to support your response.

  Emergency managers can influence policy

1. What are the differences between Hazards, Disasters and Emergencies?

  Generation of relevant hypothesis

Development of problem statements and generation of relevant hypothesis and defining of the research objective

  Profile and analysis of a business or political leader

BUS308 Contemporary Leadership Overview of Report: Leader profile. A profile and analysis of a business or political leader

  Outline and critically clarify these rights

What are the different rights of rejection a buyer has in CIF contract. Outline and critically clarify these rights

  Discuss why infomercials work

Discuss why infomercials work. Are some products better suited to infomercials?

  Best suited to a multinational internet retailer

What type of structure will be best suited to a multinational Internet retailer? Why? How would you recommend building a culture that was inclusive of diverse cultures and accommodates highly creative technical staff?

  Corporate objectives and approaches to marketing

This assessment is designed to engage you in the subject and to begin to develop an understanding of central issues in marketing.

  Problem regarding the job flexibility

Do you agree with the view that job flexibility is the key to equal pay? Express your personal viewpoints. How does equal pay affect the unemployment rate and how is it beneficial for the economy?

  Who knew that delilah was acting on behalf of someone

who knew that Delilah was acting on behalf of someone but not whom; also Giorgio, who did not know that Delilah was acting on anyone's behalf. For which contracts, if any, are you liable.

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