Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)):

image text in transcribed

image text in transcribed

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) 1) 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) 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 return O otherwise. (3 marks) In the main method, invoke all the above methods in Question 1 b) i) -11). (2 marks) c) Suppose you have a class 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) 15 marks) d) In relation to Question (d) 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 0, negative numbers, or numbers with decimal value. (3 marks) ii) Create an application class 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 (d) (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) 11) Create a dass 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

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

More Books

Students also viewed these Databases questions

Question

Why is the specific-factors model referred to as a short-run model?

Answered: 1 week ago