Using Java programme 1. 2. Create a class Account that contains two instance variables (String name, double
Fantastic news! We've Found the answer you've been seeking!
Question:
Using "Java" programme
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Solution Explanation Here I have created 2 custom exception classes that call the superclass with th... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Java Company earned net income of $85,000 during the year ended December 31, 2018. On December 15, Java declared the annual cash dividend on its 4% preferred stock (par value, $120,000) and a $0.25...
-
Using the Java program by Lenth (2011) referred to earlier, calculate power for the Adams et al. (1996) data in Table 14.2 on homophobia.
-
Java Hut leased a specialty expresso machine for a 10-year non-cancelable term. At the end of the 10-year term, Java Hut has four consecutive one-year renewal options. A replacement machine can be...
-
Information sent electronically over the Internet affords little privacy. One of the reasons that cryptography is included in this text is because its importance is growing due to the increasing need...
-
Describe the characteristics and qualities that you think are required by a good accountant.
-
The periodic time, T seconds, for a pendulum of length Lcm is T = 2 L/10. Find the approximate increase in T as L increases from 40 to 41.
-
Consider a dataset consisting of 20 observations with the following summary statistics: \(\bar{x}=0, \bar{y}=9, s_{x}=1\), and \(s_{y}=10\). You run a regression using using one variable and...
-
The Manana Corporation had sales of $60 million this year. Its accounts receivable balance averaged $2 million. How long, on average, does it take the firm to collect on its sales?
-
Discuss the impact of Consolidated Appropriation Act of 2 0 2 1 on the taxes of individuals.
-
A rod on a ball and socket joint is attached to cables A and B as in Figure. (a) If a 50-N force is exerted on the massless rod at G, what is the tensile force at cables A and B? (b) Solve for the...
-
For Starbucks identify two proactive steps our sacrifices that the organization might need to make to accomplish the goal/objectives of this organization or avert potential change related problems.
-
Internal Control Weaknesses at ABC Inc. - ACCT1198 ABC Inc. is a medium-sized manufacturing company that produces and sells electronic devices. Recently, the company discovered several internal...
-
to be reported as cash and cash equivalents, accounts receivable, and inventories are classified ?how?
-
What is the most important reason from the choices that you keep your purchase bills information up to date in your accounting system?
-
Write a memo to your CFO. Include discussion of each of these points: How the sale portion of the sale-leaseback transaction should be accounted for at the lease's inception. How the gain on the sale...
-
Evidence shows that even state and local handgun control laws work. For example, in 1974 Massachusetts passed the Bartly - Fox Law, which requires a special license to carry a handgun outside the...
-
A payoff table is given as s1 s2 s3 d1 250 750 500 d2 300 -250 1200 d3 500 500 600 What choice should be made by the optimistic decision maker? What choice should be made by the conservative decision...
-
The Place-Plus real estate development firm in Problem 24 is dissatisfied with the economists estimate of the probabilities of future interest rate movement, so it is considering having a financial...
-
In the last chapter you modified some tables for the Snick's Board Shop. Now Caitlin would like you to help her create some queries to extract information from the database. Make the following...
-
Add pictures with an OLE field to the Coast Jewelers database (use the ChlO-02 file) a. Add pictures for the remaining products in the Product table using the picture files provided. Each product has...
-
In the last chapter you modified some tables for the Wine Depot. Now Barbara would like you to help her create some queries to extract some information from the database. Make the following changes...
-
Determine the irrep content for the equivalent reducible \(S_{3}\) representations \(\Gamma^{(4)}\) and \(\Gamma^{(5)}\) of Fig. 2.4 . Data from Fig. 2.4 F(1) (2) 1 (3) (4) r(5) (6) 1 0 0 0 0 0 0 1 0...
-
Prove that the direct product of two representations is a representation, and that the character of the direct product is the product of characters for the representations.
-
Demonstrate explicitly that for invariant subgroups the cosets form a group under the coset multiplication law (2.27).
Study smarter with the SolutionInn App