Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Java programme 1. 2. Create a class Account that contains two instance variables (String name, double balance). Initially, the balance is 0. The class
Using "Java" programme
1. 2. 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 Create a Class named Bishop. Make sure the class cannot be inherited. If there have already been 5 objects initiated for this class, trying to initiate the 6th object, the constructor will throw a user-defined exception BishopCreation LimitExceeded. This class has an instance method named printObject Number which will print the object creation sequence number for the object for which you are calling the method as follows: This Bishop Object number is 3. Here, 3 is the object creation sequence number that is the third call to new Bishop() in your code that initiated the object. The BishopCreation LimitExceeded class sets the exception message (using super call in the constructor) as follows: The maximum number of bishop objects can be 5. You can define instance variables in the Bishop class if you need them.
Step by Step Solution
★★★★★
3.54 Rating (168 Votes )
There are 3 Steps involved in it
Step: 1
Solution Explanation Here I have created 2 custom exception classes that call the superclass with th...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started