Question: a) Consider the following program: public class Test T public static void main(String[] args)! System.out.print (xMethod (5.72)) public static int xMethod (int n) System.out.print(int)); return

 a) Consider the following program: public class Test T public static

void main(String[] args)! System.out.print (xMethod (5.72)) public static int xMethod (int n)

a) Consider the following program: public class Test T public static void main(String[] args)! System.out.print (xMethod (5.72)) public static int xMethod (int n) System.out.print("int")); return n) public static int xMethod (long n) { System.out.print("long")): return n;) Identify the error for the above program. (2 marks) Suggest solution to correct the error without adding more lines to the code. (2 marks) b) Write overloaded static methods for the following problems: The first function receives two integers arrays and return 1 if both arrays are equal (both arrays have the same elements at the same position). (3 marks) 11) The second function receives two strings and return 1 if the two strings are equal, irrespective of the case (lower or upper) of the strings, return 1 if the two strings are equal and retum O otherwise. (3 marks) In the main method, invoke all the above methods in Question 1 b) i) -il). (2 marks) c) Suppose you have a dass named as Number. Write a method that will display numbers from 1 to n, 7 numbers per line. The numbers are separated by one space. The method headeris as follows: public static void displayNumber(int n) (5 marks) d) in relation to Question (e) earlier 1) Create your own exception class that will handle an exception it the value of n gives by the user is invalid, such as , negative numbers, or numbers with decimal value. (3 marks) Create an application dass that will read the value of n from user and invoke the static method from Number dass in questions 1(c). Use exception dass that you have created in Question dy(i). You are required to use at least Try, Catch and Throw keywords. 19 marks) e) Create an interface named as UnitConversion. Identify TWO (2) relevant methods for the interface. (3 marks) Create a class that will use the interface that you've created in Question 1 e)i)

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!