IPL / Mr. Hansen
5/26/2011

Name: _________________________

“Big Quiz” (50 pts.) in preparation for Final Exam

 

Rules

  • Please print legibly. If you need more space, write OVER and continue on reverse.
  • If you have any questions regarding the test, do not stand up. Simply raise your hand and wait 30 seconds or so for your question to be addressed.
  • When you have finished, please start working on your assignment for Friday.

 

 

 

Part I: Terminology and Definitions (20 points; 5 points per numbered problem)

 

 

1.

Is the JVM (Java Virtual Machine) hardware, software, or neither? ________________ Explain briefly what the purpose of the JVM is. Use the term byte code in your response.

______________________________________________________________________

______________________________________________________________________

 

 

2.

What is meant by truncation? _______________________________________________

You are given a Java method that contains these lines:
     double bubbly = −4.132;

     double crubbly = 7.58;

 

What would be the result of each of the following? Fill in the blanks provided. Warning: You should know that the Math.floor method, which is the mathematical “floor” function, always returns a double.

 

            System.out.println( (int) bubbly);   // _____________

     System.out.println(Math.floor(bubbly)); // ___________

     if ( (int)crubbly==(int)Math.floor(crubbly)) {

           System.out.println("same");

     } else {

           System.out.println("different");
     }                                      // _____________

 

 

3.

In a _____________________ (starts with an “H”) object model, each class except for the root class has exactly one parent object class. Objects constructed (allocated) using a class definition are said to be _________________ (starts with an “I”) of that class. A subclass created from a higher-level class will start with all the features of the higher-order class, following an OOP paradigm known as ______________________ (starts with an “I”), except for any changed methods or data that may be present in the subclass. Such changes are an example of _________________________ (starts with a “P”), which may be defined as the ability of different objects to respond in different ways to the same messages or environment.

 

 

4.

What Java calls “methods” and what Python calls “functions” are examples of functional abstraction, or more specifically, the _____________________ (starts with an “E”) of code details within structures that other programmers should not have to tinker with. It is a general OOP strategy to isolate the ____________________ (starts with an “I”) details of any object or method from the ____________________ (also starts with an “I”) that users and other programmers can see. OOP stands for _______________________________ .

 

Part II. Longer response (points as marked)

 

 

5.
(3 pts.)





(8 pts.)

(a) Draw a state diagram to illustrate two pointers, A and B, that refer to two different objects that have been allocated from available RAM.





(b) Then explain, in clear English sentences, the standard pattern for swapping the references so that, when we are finished, A points to what B used to point to, and vice versa. Be very clear.


 

6.
(12 pts.)

Write a Java method called swapIntegers that takes as its argument an array of ints. The requirements for your method are as follows:

1. Check to see if the number of entries in the array is positive and even. If not, exit immediately with an error message.

2. Assuming the check in #1 is passed, swap entry 0 with entry 1, entry 2 with entry 3, entry 4 with entry 5, and so on until reaching the end of the array.


 

7.
(7 pts.)

Write a Python program that contains a function called brangle. Requirements for your program are as follows:

1. The brangle function should accept a nonnegative integer less than 20 as an argument. If the argument violates any of those conditions, the function should return −999. If the argument is a positive integer, the function should return the square root of the integer, using whatever method you wish.

 

2. The rest of the program should call brangle for a range of input values from −4 to 22, inclusive, and print those results, one per line.