Anda di halaman 1dari 2

Object Oriented Programming (CWD2054) February 2012 EXERCISE 7 Submission date: 25/4/2012 (Wednesday)

NAME: MATRIC NO: . SECTION: ..

QUESTION 1 An exception is an indication of a problem that occurs during programs execution. Rewrite the following program to handle arithmetic exceptions in the program:import java.util.Scanner; public class Divide { public static int Q (int A, int B) { return A/B; } public static void main( String args[ ]) { int A=10, B, result; Scanner scan = new Scanner(System.in); System.out.print(Please denominator:); B = scan.nextInt( ); result = Q(A, B); System.out.println(\nResult: result); } } (6 Marks) enter an integer

%d/%d

%d

A,

B,

QUESTION 2

State whether each of the following class definitions is legal or illegal . If illegal, explain why. a) class Calculation { abstract void aMethod( ) { } }

b) public class abstract Calculation { abstract void aMethod ( ) { } } c) class Calculation { abstract void aMethod ( ); } d) abstract class Calculation { abstract int aMethod ( ); } (8 Marks)
QUESTION 3 Write the method signature (header) for each of the following method:a) A method computeComm with computes the sales commission, given the sales amount and commission rate. All values are of type double. b) A method isEven to check if a given integer number is even or odd. The method returns true if the number is even, otherwise it returns false. (4 Marks)

*** END OF QUESTIONS ***

Anda mungkin juga menyukai