Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to perform exception handling using the information given below. Create a class called xyz to represent a Sales organization called

   

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Engineering Economy

Authors: William G. Sullivan, Elin M. Wicks, C. Patrick Koelling

15th edition

132554909, 978-0132554909

More Books

Students also viewed these Programming questions