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: 33% (3 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...
-
A heat exchanger is under development for purposes of heating liquid mercury. The exchanger can be visualized as a 6 in. long and 1 ft wide flat plate. If the plate is maintained at 160?F and the...
-
At a stage of reaction turbine, the mean diameter of rotor is \(1.4 \mathrm{~m}\). the speed ratio is 0.7. Determine the blade inlet angle if the blade outlet angle is \(20^{\circ}\). The rotor speed...
-
During May 2009, visitors to usatoday.com spent an average of 12.2 minutes per visit, compared to 11.0 minutes for visitors to washingtonpost.com. Assuming that file XR11030 contains the sample data...
-
On January 1, the first day of the fiscal year, Designer Fabric Co. issues a $850,000, 10%, 10-year bond that pays semiannual interest of $42,500 ($850,000 10% x year), receiving cash of $850,000. a....
-
(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...
-
Assume the same information as question 15, except that an indefinite-life intangible other than goodwill is being considered for write-off. How would this situation be recorded? In question 15...
-
In analysis, some focus seems to be on the need for NPV equations to be applied to projects that are mutually exclusive. But in practice we find that the lines are blurred in capital budgeting....
-
The market value of a Venturi pump averages $\$ 195.50$. There are a large number of suppliers of the pump, and prices vary only slightly from the mean, but are still normally distributed. If the...
-
In developing a capital budgeting portfolio, there are times when a project with a lower return is squeezed in to the budget but a higher-return project is excluded. How can this be fair? Wouldn't...
-
Consider a binary mixture of ideal gases, a and b, at temperature T and pressure P. Come up with an expression for in terms of T, P, and ya. What is the value of (AGmix) a
-
It was Saturday evening and Joe Johnson, VP of Patient Services, was relaxing with his family after dinner and watching a situation comedy. As the administrator on call (AOC), he was grateful things...
-
Real World Enterprises (RWE) provides a variety of backroom business services to other companies. It operates eight different facilities that employ large numbers of workers undertaking clerical...
-
The manager of a local convenience store is expanding his line of small toy items. To price these new items, the manager is looking at the prices being charged by competing retailers in his area. For...
-
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...
-
(b) Consider the following code: class TimeDuration { } // the duration can only be set during construction TimeDuration(int totalSeconds) {-} // getter methods representing the number of hours,...
-
Write the function in the form f(x) = (x-k)q(x) + r for the given value of k. = f(x) = 6x4 + 5x3 + 3x - 7x+12, k = -1 f(x) = Demonstrate that f(k) = r. (-)-
-
Consider the following MATLAB code snippet for implementing Newton's method: while( norm(f(k)) > tol & k < maxk) d = feval(dfdx,x(k)); k = k + 1; x(k) = x(k-1) - f(k-1) / d; f(k) = feval(fnon,x(k));...
Study smarter with the SolutionInn App