Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

Have you ever had what felt like an ESP experience?

Answered: 1 week ago