1. Create a class Account that contains two instance variables (String name, double balance). Initially, the balance is 0. The class also contains two methods: withdraw that takes a double parameter amount and reduces the balance value by that amount, if there is sufficient balance. Otherwise, the withdraw method throws a user-defined exception called InsufficientBalance. The other method is deposit that takes a double parameter amount and increases the balance value by that amount. For both of these methods if the argument amount passed is negative both will throw another user defined exception called InvalidAmountArgument. InsufficientBalance class's constructor takes two parameters: the current-balance and withdraw-amount whereas InvalidAmountArgument class's constructor takes only a single argument that is the negative-amount passed to those methods. The InsufficientBalance class sets the exception message (using super call in the constructor) as follows: Insufficient Balance. Current balance 100 is lower than the withdrawal amount 500. Here, the constructor parameters, current-balance value is 100 and withdraw-amount value is 500. And the InvalidAmountArgument class sets the exception message as follows: Invalid Amount Value -100. Amount can't be negative. Here, the constructor parameters, negative-amount value is -100. Now, write the classes Account and InsufficientBalance
1. Create a class Account that contains two instance variables (String name, double balance). Initially, the balance is 0. The class also contains two methods: withdraw that takes a double parameter amount and reduces the balance value by that amount, if there is sufficient balance. Otherwise, the withdraw method throws a user-defined exception called InsufficientBalance. The other method is deposit that takes a double parameter amount and increases the balance value by that amount. For both of these methods if the argument amount passed is negative both will throw another user defined exception called InvalidAmountArgument. InsufficientBalance class's constructor takes two parameters: the current-balance and withdraw-amount whereas InvalidAmountArgument class's constructor takes only a single argument that is the negative-amount passed to those methods. The InsufficientBalance class sets the exception message (using super call in the constructor) as follows: Insufficient Balance. Current balance 100 is lower than the withdrawal amount 500. Here, the constructor parameters, current-balance value is 100 and withdraw-amount value is 500. And the InvalidAmountArgument class sets the exception message as follows: Invalid Amount Value -100. Amount can't be negative. Here, the constructor parameters, negative-amount value is -100. Now, write the classes Account and InsufficientBalance
Chapter11: Exception Handling
Section: Chapter Questions
Problem 4E
Related questions
Question
Use "Java Programme "
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning