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...
-
Suppose Hewlett-Packard is considering outsourcing its telephone- based technical support functions for its printers to India. The hourly cost of a tech support person in the United States is $ 50...
-
UT Corporation has the following (incomplete) balance-sheet statement (all values are in million dollars): Balance Sheet Assets 2020 2019 Current assets 184 122 Fixed assets 690 620 Liabilities and...
-
During year end substantive procedures for cash balances as of June 30, 1999, an auditor obtains a July 10, 1999 bank statement directly from a bank. Required: Explain how the auditor will use the...
-
Rosenthal Company makes and sells products with variable costs of $24 each. Rosenthal incurs annual fixed costs of $315,000. The current sales price is $87. Required The following requirements are...
-
Explain words define globalization. Explain how trade and labor market policies can help make globalization socially sustainable. Discuss the United States' recent policy measures and how these...
-
From the tenth floor of her office building, Katherine Rally watches the swarms of New Yorkers fight their way through the streets infested with yellow cabs and the sidewalks littered with hot dog...
-
How many of the following accounts (line items) are found on the income statement? Accounts Receivable Sales Revenue Cash Collected from Customers Wages Payable Wages Expense Depreciation Expense...
-
T/F: SAPs model the knowledge of the problem domain.
-
List and describe two scenarios of competition of each of the following areas: a. Culture b. Economy c. Law d. Social life and society
-
Explain some of the known usages of competition pattern in day-to-day life. List a few that are not covered in the chapter.
-
Name three samples of traditional analysis patterns developed using specialization approach.
-
What EBTs can be brought under the umbrella of stable analysis pattern?
-
When does a switch flood the network with a frame? When it does not know the destination IP address For every frame When the frame uses the UDP protocol When there is no MAC address associated with a...
-
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...
-
Consider a gas metal arc welding electrode as shown in Figure P10.29 where we are consuming the electrode as we weld ( rod velocity \(\left.=v_{o} ight)\). We are interested in the steady-state...
-
Consider the heat transfer to a falling film problem of Section 10.3. The mass transfer analog is the dissolution of a solid wall into the falling film. Assuming the solid wall is composed of salt,...
-
In Smoluchowski's Theory of Coagulation we focus on an individual sphere and assume that other like particles diffuse toward it. Once they reach the sphere, they collide and form a new spherical...
Study smarter with the SolutionInn App