Write a Java program to perform exception handling using the information given below. Create a class...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Java program to perform exception handling using the information given below. Create a class called xyz to represent a Sales organization called xyz. This xyz organization has employees working under different departments. This xyz class has the following variables. Use Scanner class to get the input for the following variables from the user. - Employee name - String datatype - Employee ID - integer datatype - Employee designation - String datatype The options for employee designation are: Head / Manager / Account manager/ Sales representative If the designation of the employee is Head or CEO then get the input for the following variable: - number of years of experience - integer datatype variable If the number of years of experience of the Head is lesser than 5 years then throw an ArithmeticException If the designation of the employee is Manager then get the input for the following two variables: - get the input for the department name of the manager - String datatype variable - Number of employees working in this employee's department - integer datatype variable If the number of employees working in a department is greater than 100, then throw an ArrayIndexOutOfBoundsException If the designation of the employee is Account Manager, then get the input for the following variable: - Yearly turn-over of the organization during the previous year - integer datatype variable If the yearly turn-over is equal to zero, then throw an InputMismatchException. If the designation of the employee is Sales representative, then get the input for the following two variables: - Number of sales completed for the previous month - integer datatype variable - Total number of cities travelled during the previous month - integer datatype variable If the total number of cities travelled is equal to zero, then throw an IllegalArgumentException Use the corresponding catch blocks to handle the different types of exceptions mentioned above. Display the values of the variables before the occurrence of the exception and also display the statements within the catch block which perform exception handling of the different types of exceptions which get thrown under each specific occasion mentioned in the question above. Also display the exception message of the caught exception using getMessage() method. Sample output: Enter the employee name : abc Enter the employee ID: 9 Enter the employee designation: Head Enter the number of years of experience : 3 Exception caught: java.lang.ArithmeticException Years of experience is < 5 Exception message: Years of experience < 5 Another sample output: Enter the employee name: fgh Enter the employee ID: 90 Enter the employee designation: Account Manager Enter the yearly turn-over of the organization during the previous year: 0 Exception caught: java.lang.InputMismatchException: Turn-over of the organization during the previous fiscal year is equal to zero Exception message: Turn-over of the organization during the previous fiscal year is equal to zero Write a Java program to perform exception handling using the information given below. Create a class called xyz to represent a Sales organization called xyz. This xyz organization has employees working under different departments. This xyz class has the following variables. Use Scanner class to get the input for the following variables from the user. - Employee name - String datatype - Employee ID - integer datatype - Employee designation - String datatype The options for employee designation are: Head / Manager / Account manager/ Sales representative If the designation of the employee is Head or CEO then get the input for the following variable: - number of years of experience - integer datatype variable If the number of years of experience of the Head is lesser than 5 years then throw an ArithmeticException If the designation of the employee is Manager then get the input for the following two variables: - get the input for the department name of the manager - String datatype variable - Number of employees working in this employee's department - integer datatype variable If the number of employees working in a department is greater than 100, then throw an ArrayIndexOutOfBoundsException If the designation of the employee is Account Manager, then get the input for the following variable: - Yearly turn-over of the organization during the previous year - integer datatype variable If the yearly turn-over is equal to zero, then throw an InputMismatchException. If the designation of the employee is Sales representative, then get the input for the following two variables: - Number of sales completed for the previous month - integer datatype variable - Total number of cities travelled during the previous month - integer datatype variable If the total number of cities travelled is equal to zero, then throw an IllegalArgumentException Use the corresponding catch blocks to handle the different types of exceptions mentioned above. Display the values of the variables before the occurrence of the exception and also display the statements within the catch block which perform exception handling of the different types of exceptions which get thrown under each specific occasion mentioned in the question above. Also display the exception message of the caught exception using getMessage() method. Sample output: Enter the employee name : abc Enter the employee ID: 9 Enter the employee designation: Head Enter the number of years of experience : 3 Exception caught: java.lang.ArithmeticException Years of experience is < 5 Exception message: Years of experience < 5 Another sample output: Enter the employee name: fgh Enter the employee ID: 90 Enter the employee designation: Account Manager Enter the yearly turn-over of the organization during the previous year: 0 Exception caught: java.lang.InputMismatchException: Turn-over of the organization during the previous fiscal year is equal to zero Exception message: Turn-over of the organization during the previous fiscal year is equal to zero
Expert Answer:
Related Book For
Engineering Economy
ISBN: 978-0132554909
15th edition
Authors: William G. Sullivan, Elin M. Wicks, C. Patrick Koelling
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
Given that the notion of HRM is seen in some countries to be more advanced than the idea of personnel management, why might the latter continue to be the preferred terminology in most of Europe?
-
Where does this body of law or legal tool fit in the value chain?
-
Corporations are subject to a flat income tax rate of 21%; individuals have graduated rates from 10% to 37%. Does this make the corporate entity a better entity choice for tax purposes? Explain.
-
A textile company, wanting to know the effect of temperature on the tearing strength of a fiber, obtained the data shown in the following table. (a) Draw a scatter plot to verify that a straight line...
-
1. What are some things Colin could have done in or after the meeting when Henri verbally attacked him? 2. Is there anything more Raouf could have done during or after his meeting with Colin to...
-
How can conflict theory proposed a solution for crime and education in a community? Provide references!
-
The controller at Ranyah Corporation analyzed a proposed equipment purchase for the firm and decided that the investment met all the firms criteria regarding payback, net present value, and internal...
-
Swifty Company received proceeds of $159800 on 10-year, 8% bonds issued on January 1, 2018. The bonds had a face value of $170000, pay interest annually on January 1, and have a call price of 101....
-
Explain the interdependent nature of stressors, stress, and adaptation. Differentiate the physical and emotional responses to stress, including local adaptation syndrome, general adaptation syndrome,...
-
Trinity, a 51-year-old taxpayer, earned $54,000 in wages. What is the maximum deductible amount of contribution she can make to a 401(k) plan for 2023? Show your calculations.
-
Zero rates for one year, two year and 3 year investments are 4%, 5% and 5.6% per annum with continuous compounding. What is the forward rate for year 3 (% per annum with continuous compounding)?
-
Money is borrowed at 7 % simple interest. After one year, $ 1 0 9 6 . 7 5 pays off the loan. How much was originally borrowed?
-
In what situations might a company want to use a non-human charactering their messaging?
-
Using (1) or (2), find L(f) if f(t) if equals: t cos 4t
-
The length of a straight solenoid is \(50 \mathrm{~cm}\). If a current of 12 A flows through the solenoid produces a magnetic field of magnitude \(0.06 \mathrm{~T}\) inside it, calculate the number...
-
Two parallel rods having length \(12 \mathrm{~cm}\) and a separation of \(50 \mathrm{~cm}\) carry current from left to right. If current through wire 1 is \(10 \mathrm{~A}\) and through wire 2 is...
-
A wire segment of \(1.0 \mathrm{~m}\) and carrying a current of \(5.0 \mathrm{~A}\) is held in a plane in which it can rotate and translate with little friction. A long wire is fixed parallel to this...
Study smarter with the SolutionInn App