Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A method that returns a special error code can sometimes cause problems. The caller might ignore the error code or treat the error code

 image

A method that returns a special error code can sometimes cause problems. The caller might ignore the error code or treat the error code as a valid return value. In this case it is better to throw an exception instead. The following class maintains an account balance and returns a special error code. public class Account private double balance; public Account() balance = 0; } public Account(double initialDeposit) { balance = initialDeposit; public double getBalance() return balance; } // returns new balance or -1 if error public double deposit(double amount) if (amount > 0) else balance + amount; return -1; // Code indicating error return balance; // returns new balance or -1 if invalid amount { public double withdraw(double amount) if ((amount > balance) || (amount < 0)) else return -1; balance amount; return balance; You have to provide your solution with the following guidelines. Rewrite the class so that it throws appropriate exceptions instead of returning -1 as an error code (7 marks) Write client class to use this Account class that attempts to withdraw and deposit invalid amounts and catches the exceptions that are thrown. (9 marks) Make sure you explain and justify every line of your code using internal documentation. (5 marks) Provide a test plan using a test table similar to the one in Assignment 2 to explain and justify how you will test the code. You are not required to provide the actual output, just provide the Expected Output. (6 marks) Provide the structure diagram and the class diagram for the code. (5 marks). Explain the advantages of using exception for this case (3 marks).

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

Step: 1

Java public class Account private double balance public Account balance 0 p... 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

Macroeconomics Principles Applications And Tools

Authors: Arthur O Sullivan, Steven M. Sheffrin, Stephen J. Perez

7th Edition

978-0134089034, 9780134062754, 134089030, 134062752, 978-0132555234

More Books

Students also viewed these Programming questions