Está en la página 1de 8

0 1 2 3 4 5 6 7 8

Exam 1
EE 322C - University of Texas at Austin - Sample Exam

Name ____________________________________

Test taking instructions. No calculators, laptops or other assisting devices are allowed. Write
your answers on these sheets. Wherever code is required, write Java statements in the blank areas
provided, or by modifying the given code in place. You are not required to follow the coding
style guidelines when writing code on the exam, but be as neat as possible. If you are unsure of
the meaning of a specific test question, then write down your assumptions and proceed to answer
the question on that basis. If you see a typo or syntax error, fix it, circle it, and if you are right
you will get a bonus point for each one fixed. In your programming solutions on this test you
may use any of the methods that you know from the library. You may use the Java Collections
Framework classes that we have covered in class. Questions about the meaning of an exam
question will not be answered during the test!

0. Program Measurements [ 3 points ]. For your programming assignments 1-2 fill in the table
below by providing the data required to answer:
- how big was each program (in SLOCs)?
- how many hours of effort did you expend on each (in approximate person hours)?
- how many serious logic defects did you have to fix to get it working?

Assignment # of SLOC Person # of logic


hours defects
1
2

SLOC (source lines of code) – Each physical line in the source code listing counts as 1 SLOC.
However, lines which are only comments and blank lines are not included in this count. Code
modules included from the Java libraries do not count, but the import statement does. Only
SLOC delivered in the final submitted .java file for grading should be counted. For assignment 2
do not count the BankAccount class that was given to you – just the ones you wrote.

The unit of measure for effort is a person hour which is defined as: " an hour of time expended
by you in the course of doing the assignment".
A defect is a flaw in your program that causes it to not work properly. This includes both run-
time errors and logic errors. We are interested in the number of serious errors that you
encountered and had to fix in completing the assignments. Serious means that it was not
immediately obvious what the problem was.
Page 2

1. Terminology. [23 pts.] Answer each of the following questions by choosing the best answer
from the list below.
A. ____a type of variable which points to an object or an array
B. ____a method that is defined in the Object class
C. ___ a modifier that makes a variable constant
D. ___ a class that encapsulates a primitive type within an object
E. ___ the use of a parameterized data type
F. ___ a method that establishes the starting point in a pseudorandom number sequence
G. ____wrapping a primitive type into an object representation
H. ____an assumption or constraint on a method’s data before it executes
I. ____a method or variable that is visible to any class in your program
J. ___ a method or variable that is visible only to objects from the class in which it is
defined
K. ___ a variable which is only known within the block that contains its declaration
L. ____a variable or expression contained in a method call inside of the ( )
M. ____a special method with the same name as the class name
N. ___ a method that examines an object but does not change its data values
O. ____hiding the details of a class’s implementation from its users
P. ____examples of this are int, float, char, and boolean
Q. ____the relationship between a class and a subclass in Java
R. ____the representation scheme for characters in Java
S. ____the portable intermediate language that is interpreted by the Java Virtual Machine
T. ___ a kind of method that is not associated with (or called by) an object
U. ___ a generic data structure that stores a large group of elements with common operations
for adding, removing and accessing elements.
V. ___ an integral type associated with Collections that can be used to cycle through the
elements.
W. ___ a sequence collection that provides direct access through an index and grows
dynamically at the rear

a) abstraction r) formal parameters ii) precondition


b) accessor s) generic jj) public
c) argument t) goto kk) reference
d) ArrayList u) half word ll) relational
e) ASCII v) increment mm) RGB
f) Autoboxing w) information hiding nn) set
g) BCD x) instance oo) setSeed
h) bytecode y) iterator pp) shadowed
i) class z) layout qq) String
j) clone aa) local rr) Swing
k) collection bb) logical ss) static
l) constructor cc) mutator tt) Unicode
m) conversion dd) object uu) Void
n) declaration ee) package vv) wrapper
o) decrement ff) primitve type
p) extends gg) private
q) final hh) process
Page 3
2. Multiple Choice. [2 pts. each = 16 pts. Total] For each of the following choose all correct
answers. Circle them.

A. Which of the following statements is NOT a purpose of a Java class?


i. A template used to create objects of that type
ii. Specifies methods to use on objects of that type
iii. Defines the common attributes of all objects in the class.
iv. Create a programmer defined data type
v. Defines the state values for specific objects of that type

B. What does the following statement do?

FileReader infile = new FileReader("test.txt");

i. It creates a new file named test.txt if it does not exist and opens the file so you can write to it.
ii. It creates a new file named test.txt and opens the file so you can write to it and read from it.
iii. It creates a new file named test.txt regardless of whether it exists or not and opens the file so you
can read from it.
iv. It locates an existing file named test.txt and opens the file so you can read from it. If the file is
not found it throws an exception.
v. None of the above is correct.

C. Which of the below is not a basic part of Java?


i. the Java Language iii. JavaScript
ii. the Java Libraries iv. the Java Virtual Machine

D. Which of the following statements is NOT true?

i. A method's parameters are local to that method.


ii. A method's header must specify a type for each parameter.
iii. The type of an actual argument must be the same as the type of the corresponding formal
parameter.
iv. Methods that return a value may have no parameters.
v. A method body could contain no statements

E. The core activities that are found in all software development lifecycle models, such as those shown
in my lecture notes, are:

i. Requirements
ii. Design
iii. Implementation
iv. Testing
v. Delivery
vi. None of the above

F. Some of the fundamental software design concepts that help manage complexity are the use of:
i. abstractions for data, procedure, and control
ii. compartmentalization of data and function into logical sub units called modules
iii. information hiding by creating controlled interfaces and hidden implementation details
iv. functional independence using single-minded functions with high cohesion and low coupling
v. stepwise refinement for the incremental elaboration of detail for all abstractions
Page 4

G. An Iterator uses which of the following methods:


i. hasNext
ii. next
iii. remove
iv. add
v. previous

H. A Java interface:
i. has all abstract methods
ii. can be implemented by many other classes
iii. can be extended by an abstract class
iv. can extend more than one other interface
v. can contain variable and constant declarations

3. Program debugging - Find and Fix. [8 pts.]


Given below is the method that was presented in class that is supposed to compute the reverse of a given
string when called by main. Find, circle and fix all bugs found in this code. (Hint: there is at least 1
syntax error, and at least 1 logic error).

public class MakeNewStrings


{ public static void main (String [ ] args)
{ Scanner input = new Scanner (System.in );
System.out.println (“Please input a string to be reversed”);
String s = in.nextLine ( );
s = reverseMethod (s);
System.out.println ("The converted string is " + s);
}
static String reverseMethod (String phrase)
{ int i =0, char ch;
String reversed;
reversed = “”;
while (i < phrase.length()) ;
{ ch = phrase.charAt(i);
// concatenate ch onto the front-end of reversed
reversed = ch + reversed;
i = i - 1;
}
return reversed;
}
}
Page 5
4. Class Definition [10 points] The following code is similar to the example in Chapter 3 (the address
is changed to a string for simplicity). It demonstrates how multiple inheritence is faked in Java by using
interfaces. Given the code for the 2 interfaces below (EmployeeInt and StudentInt), fill in the code for
the StudentWorker class that implements both interfaces. You may assume that the Student and
Employee classes exist and that Student and Employee implement their respective interfaces. Your code
needs to show how the StudentWorker class refers to the student and employee parts of an object. Your
code also needs to show (at a minimum) the constructor, and the get methods for a student worker using
delegation for their implementation.

public interface EmployeeInt


{
String getName();
double getHours();
double getRate();
String getAddress();
}
public interface StudentInt
{
String getName();
double getGPA();
String getMajor();
String getAddress();
}
public class StudentWorker _________________________________
{

}
Page 6

Question 5. [10 points] Change the following sequential search method into a generic method that will
work for any given type of array of numeric objects.

public static int sequentialSearch (final int arr[ ], int target)

{ /** purpose – a method to perform a sequential search on the given array looking for the given target

value

@param – arr [] is the array passed to the method over which the search is performed

@param – target is the value to be searched for

@return – the method returns the index of the target in arr if found, or a -1 if not found

*/

int i = 0;

// test for a match or index out of range.

while(i < arr.length && arr[i] != target) {i++;}

if (i = = arr.length ) return -1;

else return i;

}
Page 7
Question 6. Code Writing [10 points ]
A. Finish the implementation of the static method below whose purpose is to return a ArrayList which
contains the union of two given integer ArrayLists v1 and v2. The union includes all those elements
that are found in either of the two ArrayLists. The resultant ArrayList must be without duplicates.
You may assume that the values in v1 and v2 are integers that are in no particular order. Document
the pre and post conditions for this method as well.

public static ArrayList<Integer> union (ArrayList<Integer> v1, ArrayList<Integer> v2)


{

}
Page 8
Question 7. Design [10 Points] A hospital has different kinds of patients who require different
procedures for billing and for approval of medical procedures to be done. Some patients have insurance,
but some do not. Of the insured patients, some are on Medicare (US Government provided), some are in
Health Maintenance Organizations (HMOs), and some have other health insurance providers.

Design a UML Class Diagram to show the relationships between these different kinds of patients for use
in a Patient Management System. You choose which attributes and behaviors of each class are essential
to show in the model.

Question 8 [10 points] Write a static method that takes a string as its argument which contains a
phrase of words separated by one or more spaces, and reverses the words and returns a string with the
words reversed.

For example, when given the string “Mary had a little lamb”, the method returns “lamb little a had
Mary”

También podría gustarte