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

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 4E
icon
Related questions
Question

Use "Java Programme "

 

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning