Question: Lab Exercise: Complete the code The following code will read a score form the user. The exception will be thrown with an appropriate message in

Lab Exercise:

Complete the code

The following code will read a score form the user. The exception will be thrown with an appropriate message in the following cases:

If the score is greater than 100.
If the number is negative.

If the score is less than 60 and not negative then "Not Passed" message will be displayed.

If the score is between 60 and 100 then " Success! the entered score is ." will be displayed.

See the output to have better understanding.

import java.util.Scanner;

public class ExceptionTest {

public static void main( String args[] ){

// input the number from user in the try block

Scanner input = new Scanner (System.in);

try{

int number = input.nextInt();

System.out.println(checkScore(number));

}

catch(Exception ex){

System.out.println(ex.getMessage());

}

} // end main method

// lessThan60 method will throw an exception if the number is negative

// otherwise it will retuurn the string "Not passed".

public static String lessThan60( int number ) throws Exception

{

}

// checkScore method will thrwo an exception if the number is greater than 100.

// else if the number is less than 60 the lessThan60 method will be invoked.

// otherwise the string ("Sucess! the entered score is "+number) will be returned.

public static String checkScore( int number ) throws Exception

{

}

}

Sample output :

90

Success! the entered score is 90

200

java.lang.Exception: the entered score is higher than 100

40

Not passed

-70

java.lang.Exception: the entered score is negative!

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!