This is JAVA.... Fill in the blanks (10 points) A _____________________ is needed to terminate recursion. A mouseDragged method call is preceded by a ___________________ method call and followed by a...




This is JAVA....



Fill in the blanks
(10 points)


A _____________________ is needed to terminate recursion.


A mouseDragged method call is preceded by a ___________________ method call and followed by a ___________________ method call.


An uncaught exception is an exception that occurs for which there are no matching ________ blocks.


Class ___________ and its subclasses represent problems that could occur in Java program and be caught by the application.


Subclasses of RuntimeException represent _________________ exceptions.


The _____________ block is optional. If it is present, we place it after the last catch block.


Iteration normally uses a ___________ statement whereas recursion normally uses a __________________ statement.


A superclass’s ______________ and _____________ members can be accessed in the superclass declaration and in subclass declaration.


The _________________ method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.


To create an immutable class like the String class, we use the keyword ________________ in the class declaration.



Write True or False. If False, explain why? (5 points)


1. When a programmer creates a JFrame, a minimum of at least one menu with two menu items must be created and added to the JFrame.


2. A “has-a” relationship is implemented via inheritance.


3. A Car class has a “has-a” relationship with the Brakes class and Engine class.


4. All methods in an abstract class must be declared as abstract methods.


5. A static import declaration (usually the packageName.className.*) enables you to refer to imported static members of a class without the className and a (.) dot.



Answer the following questions


1. Assume you have the following list:(4 points)


13, 23, 24, 34, 35, 36, 38, 42, 47, 51, 68, 74, 75, 85, 97


Using the binary search executed in chapter 14, how many key comparisons are required to determine whether the following items are in the list? Show the values of first, last, and middle and the number of comparisons after each iteration of the loop. Explain.


a. 23







































































Iteration




first




last




mid




list[mid]




No of comparisons



1



2



3



4



5



6



7



b. 75







































































Iteration




first




last




mid




list[mid]




No of comparisons



1



2



3



4



5



6



7



2. Consider the following method:(4 points)


public static int secret (int one)


{



int i;



int prod = 1;



for (i = 1; i <=>



prod = prod * one;



return prod;


}


a. What is the output of the following Java statements? Explain your answer.


i. System.out.println(secret(5));


ii.System.out.println( 2 * secret(6));


b. What does the method secret do?


3. Consider the following recursive method:(5 points)


public static void recFun(int x)


{



if ( x > 10)



{



recFun(x/10);



System.out.println( x % 10);



}



else



System.out.println(x);


}


What is the output of the following statements?
Explain.


a.) recFun(258);


b.) recFun(67);


c.) recFun(-7);


4. Consider the following method:(4 points)


public static int test(int x, int y)


{



if (x == y)



return x;



else if (x > y)



return (x + y);



else



return test(x + 1, y - 1);


What is the output of the following statements?
Explain.


a.) System.out.println(test(5, 10));


b.) System.out.println(test(3, 9));


5. Name three exception handling techniques. Explain and provide examples.(6 points)


6. What is the output of the following java code?
Explain your answer.
(5 points)



final double PI = 3.14159;

double[] cylinderRadii = {3.5, 7.2, 10.5, 9.8, 6.5};

double[] cylinderHeights = {10.7, 6.5, 12.0, 10.5, 8.0};

double[] cylinderVolumes = new double[5];



for(int i = 0; i <>

cylinderVolumes[i] = 2 * PI * cylinderRadii[i]



* cylinderHeights[i];





for (int i = 0; i <>

System.out.printf("%d %5.2f %5.2f %7.2f %n",

(i + 1), cylinderRadii[i], cylinderHeights[i],


cylinderVolumes[i]);



6.
Suppose that class Three is derived from class Two and class Two is derived from class One and each class has instance variables. Suppose that an object of class Three enters its scope, so the constructors of these classes will execute. Determine the order in which the constructors of these classes will execute. Explain.
(2 points)







May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here