Question: Write a class called Excp01 with a main method. Write a method of Excp01 called myMethod, whch has no arguments an returns void. This is

Write a class called Excp01 with a main method. Write a method of Excp01 called myMethod, whch has no arguments an returns void. This is what myMethod does: 1. prompts the user for an int (less than 10 and larger than 0), lets call it n. 2. loops n times 3. each time it prompts the user to enter another integer, call it x 4. if x is less than 0 or greater than 100 the constructo throws an exception called IllegalArgumentException 5. IllegalArgumentException must display the message: "Exception thrown--number: " followed by the value of x. 6. if no IllegalArgumentException is thrown, the program must print the average of all numbers entered. 7. after printing the average, ask the user for another int (smaller than 200) and just display it. (see examples below for details) 8. Everytime this program reads an number from the user it must use exception in order to avoid crashing.

Restrictions

1. use exactly one throw exception.

2. don't use more than 2 try/catch blocks.

Examples :

% java Excp01 enter nr of integers (max 10) to be processed: q w try again, enter an int: 2.3 try again, enter an int: 3 ok, now lets loop 3 times enter an int: 10 enter an int: 0 enter an int: q w try again, enter an int: 2.3 try again, enter an int: 5 average is: 5.0 enter an integer less than 200: 300 out of bounds, try again, enter an int: q w try again, enter an int: 2.3 try again, enter an int: 100 integer was: 100 % java Excp01 enter nr of integers (max 10) to be processed: 3 ok, now lets loop 3 times enter an int: 200 Exception thrown--number: 200 % java Excp01 enter nr of integers (max 10) to be processed: 3 ok, now lets loop 3 times enter an int: 2.0 try again, enter an int: 5 enter an int: 6 enter an int: 3.4 try again, enter an int: 7 average is: 6.0 enter an integer less than 200: 100 integer was: 100 % java Excp01 enter nr of integers (max 10) to be processed: 3 ok, now lets loop 3 times enter an int: q try again, enter an int: 10 enter an int: 1 enter an int: 2 average is: 4.333333333333333 enter an integer less than 200: 3 integer was: 3 % java Excp01 enter nr of integers (max 10) to be processed: 20 out of bounds, try again, enter an int: 3 ok, now lets loop 3 times enter an int: 1 enter an int: 2 enter an int: 3 average is: 2.0 enter an integer less than 200: 6 integer was: 6 %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!