Modify class Account (Fig. 7.8) to provide a method called withdraw that withdraws money from an Account.
Question:
Modify class Account (Fig. 7.8) to provide a method called withdraw that withdraws money from an Account. Ensure that the withdrawal 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 "Withdrawal amount exceeded account balance." Modify class AccountTest (Fig. 7.9) to test method withdraw.
Fig. 7.8
Fig. 7.9
Transcribed Image Text:
I // Fig. 7.8: Account.java 2 // Account class with a double instance variable balance and a constructor // and deposit method that perform validation. 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 public class Account { private String name; // instance variable private double balance; // instance variable 40 41 } // Account constructor that receives two parameters public Account (String name, double balance) { this.name = name; // assign name to instance variable name } // method that deposits (adds) only a valid amount to the balance public void deposit (double depositAmount) { if (depositAmount > 0.0) { // if the deposit Amount is valid balance + depositAmount; // add it to the balance } // validate that the balance is greater than 0.0; if it's not, // instance variable balance keeps its default initial value of 0.0 if (balance > 0.0) { // if the balance is valid this.balance = balance; // assign it to instance variable balance // method returns the account balance public double getBalance() { return balance; } } } // method that sets the name public void setName(String name) { this.name = name; } // method that returns the name public String getName() { return name;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 40% (5 reviews)
To fulfill the requirements of the given assignment you should add a withdraw method to the Account class that allows the withdrawal of funds provided the amount does not exceed the account balance He...View the full answer
Answered By
Amit Choudhary
I'm new in this profession regarding online teaching but previously i used to teach students near my college. I am teaching on online platform since last year and got good support from the students. I'm teaching on platforms like chegg and vedantu and also at my home in free time.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Create an inheritance hierarchy that a bank might use to represent customers bank accounts. All customers can deposit (credit) into their accounts and withdraw (debit) from their accounts. More...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Prepare the schedule of year-end deferred tax assets and liabilities for each year. The schedule should separately list the sources of the firms ending deferred tax assets and deferred tax...
-
(Stock-Option Plan) Berg Company adopted a stock-option plan on November 30, 2009, that provided that 70,000 shares of $5 par value stock be designated as available for the granting of options to...
-
You are provided with the projected income statements for a project: ¢ The tax rate is 40%. ¢ The project required an initial investment of $15,000 and an additional investment of $2,000 at...
-
Think about a job or a volunteer role where your hygiene needs were not met. What was the effect of this on your level of motivation?(p. 93)
-
Frankton Corporation has experienced difficult financial times for the past five years resulting in serious cash flow problems, negative earnings, and increasing deficits in retained earnings. The...
-
A portfolio return can be calculated by: taking the simple average of the individual stock returns . i.e. add up the returns of the individual stock in the portfolio and divide by the number of...
-
(Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance...
-
State whether each of the following is true or false. If false, explain why. a) An import declaration is not required when one class in a package uses another in the same package. b) Variables...
-
Top managers of Walsh Products, Inc., have asked for your help in comparing the companys profit performance and financial position with the average for the industry. The accountant has given you the...
-
1. (5 pts) Given y[n]= 2y[n-1] and y[0]=2, Write MATLAB code to calculate and plot y for 0
-
F ( t ) = t 4 + 1 8 t 2 + 8 1 2 , g ( t ) = ( t + 3 ) / 3 ; find ( f o g ) ( 9 )
-
How did they calculate allocated cost FLIGHT A FLIGHT 350 615 FLIGHT 3 1 Go GALS 20 G EXISTING SCHEME, DETERMINE THE OVE OR FLIGHTS A, B, AND C. 2 ED AT 7.00 PER K1.00 OF PILOT SALAF TOTAL NON-SALARY...
-
High Tech ManufacturingInc., incurred total indirect manufacturing labor costs of $540,000. The company is labor-intensive. Total labor hours during the period were 5,000. Using qualitativeanalysis,...
-
Start with AS/AD and IS/MP in full employment equilibrium. Assume the is a massive positive aggregate demand shock. How would this affect AS/AD and IS/MP and prices and output relative to the full...
-
A U.S. postal zip code is a five-digit number. a) How many zip codes are possible if any of the digits 0 to 9 can be used? b) If each post office has its own zip code, how many possible post offices...
-
Consider a closed, rigid tank with a volume of 0.8L, filled with cold water initially at 27C. The tank is filled such that there are no voids (air pockets) within. The initial pressure within the...
-
Give an efficient algorithm that computes and prints, for every position p of a tree T, the element of p followed by the height of ps subtree.
-
For a tree T, let n I denote the number of its internal nodes, and let n E denote the number of its external nodes. Show that if every internal node in T has exactly 3 children, then n E = 2n I +1.
-
Let T be a (possibly improper) binary tree with n nodes, and let D be the sum of the depths of all the external nodes of T. Describe a configuration for T such that D is Ω(n 2 ). Such a...
-
Duncan Inc. issued 500, $1,200, 8%, 25 year bonds on January 1, 2020, at 102. Interest is payable on January 1. Duncan uses straight-line amortization for bond discounts or premiums. INSTRUCTIONS:...
-
WISE-HOLLAND CORPORATION On June 15, 2013, Marianne Wise and Dory Holland came to your office for an initial meeting. The primary purpose of the meeting was to discuss Wise-Holland Corporation's tax...
-
Stock in ABC has a beta of 0.9. The market risk premium is 8%, and T-bills are currently yielding 5%. The company's most recent dividend is $1.60 per share, and dividends are expected to grow at a 6%...
Study smarter with the SolutionInn App