2. Write a program named CommonExceptionDemo.java to accomplish the following tasks: (1) Displays the info(name and ordi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

2. Write a program named CommonExceptionDemo.java to accomplish the following tasks: (1) Displays the info(name and ordi

Post by answerhappygod »

2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 1
2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 1 (44.07 KiB) Viewed 16 times
2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 2
2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 2 (30.21 KiB) Viewed 16 times
2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 3
2 Write A Program Named Commonexceptiondemo Java To Accomplish The Following Tasks 1 Displays The Info Name And Ordi 3 (25.81 KiB) Viewed 16 times
2. Write a program named CommonExceptionDemo.java to accomplish the following tasks: (1) Displays the info(name and ordinal value) of every element in an enum ExceptionEnum. (2) Asks the user to input a integer. (3) According to the value of user's input, triggers the Exception • While getting the input value, uses try-catch to check. • If the input is a number and its value is between 0 and 5, triggers the Exception in ExceptionEnum and shows its information. • If the input is a number but its value is not between 0 and 5, throws an IllegalArgumentException, catches it and prints the exception message. • If the input is not a number, triggers Input MismatchException, catches it and prints the exception message.

import java.util. Input MismatchException: import java.util.Scanner: en Exceptionnum ARITHMETIC INDEXOUTOFBOUNDS, NEGATIVEARRAYSIZE, NULLPOINTER, NUMBER FORMAT CLASSCAST: private Exceptione: public Exception getException ) { return e; Complete codes for the method public static ExceptionEnum getExceptionByordinal (int ord) throws IllegalargunentException ! //Complete code here. This method returns the element whone ordinal value is the same with ord //and throw an legalArgumentException to alert the value of ord is not in the range of 0.5 1 Hint: Using switch-case to check which status matches the ord value. In each case, new an exception object(or instance) associated with the exceptionEnum, and return one of the ExceptionEnum of the enumerated type. Otherwise, throws an illegalArgumentExpection. public class CommonExceptionDemo public static void main(string] args) { 1/complete code in main method to show your running result like output sample

Output sample: Exception: ARITHMETIC(O) The program has been INDEXOUTOFBOUNOS(1) run for three times. NEGATIVEARRAYSIZE (2) NULLPOINTER(3) When you create an ArithmeticException NUMBERFORMAT (4) CLASSCAST(5) object, please invoke its constructor with Exception: argument "/ by zero" ARITHETIC(O) Please input an integer to select the TYPE OF EXCEPTION(-5):0 INDEXOUTOFBOUNDS (1) java.lang.ArithmeticException by zero NEGATIVEARRAYSIZE(2) at Exceptionnum.getExceptiondyOrdinal (Common xceptionDemova:21) NULLPOINTER(3) at CommonExceptionDeo, main(Commonixceptionem. 12:56) NUMBERFORMAT(4) CLASSCAST (5) Plesse Input an Integer to select the TYPE OF EXCEPTION(6-5) java.util. Inutiseatchboxception Here is the End Exception ARITHMETIC(O) INDEXOUTOFBOUNDS (1) NEGATIVEARRAYSIZE(2) WOLLPOINTER(3) NUMBER FORT(4) CLASSCAST (5) Please input an integer to select the TYPE OF EXCEPTION(O) 17 java.lang. IllegalArgumentException Here is the End
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply