Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is JAVA.... Fill in the blanks (10 points) A _____________________ is neede

ID: 3676466 • Letter: T

Question

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 <= 3; 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 < 5; i++)
       cylinderVolumes[i] = 2 * PI * cylinderRadii[i]

                        * cylinderHeights[i];
                         
        
   for (int i = 0; i < 5; i++)
       System.out.printf("%d %5.2f %5.2f %7.2f %n",
           (i + 1), cylinderRadii[i], cylinderHeights[i],                                                 

cylinderVolumes[i]);

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

Iteration

first

last

mid

list[mid]

No of comparisons

1

2

3

4

5

6

7

Explanation / Answer

FILL IN THE BLANKS

A return is needed to terminate recursion.

A mouseDragged method call is preceded by a mousePressed method call and followed by a mouseReleased method call.

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

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

Subclasses of RuntimeException represent unchecked exceptions.

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

Iteration normally uses a repetition statement whereas recursion normally uses a selection statement.

A superclass’s public and protected members can be accessed in the superclass declaration and in subclass declaration.

The system.gc 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 final in the class declaration.

True or False

1.False. A JFrame does not require any menus.

2. False

3. False

4. False

5.True

a. 23

Iteration

first

last

mid

list[mid]

No of comparisons

1

0

14

7

38

2

2

0

6

3

24

2

3

0

2

1

23

2

4

5

6

7

b. 75

Iteration

first

last

mid

list[mid]

No of comparisons

1

0

15

8

42

2

2

9

15

12

74

2

3

13

15

14

85

2

4

13

13

13

75

5

6

7

2. a. i) 125

2.a ii) 432

3 a.) recFun(258); Ans 2

3 b.) recFun(67); Ans 6

3 c.) recFun(-7); Ans -7

Iteration

first

last

mid

list[mid]

No of comparisons

1

0

14

7

38

2

2

0

6

3

24

2

3

0

2

1

23

2

4

5

6

7

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote