Professional Documents
Culture Documents
1.00/1.001 Introduction To Computers and Engineering Problem Solving Fall 2002
1.00/1.001 Introduction To Computers and Engineering Problem Solving Fall 2002
001
Introduction to Computers and Engineering Problem Solving
Fall 2002
Name:
TAs Name:
Tutorial:
For Graders
Question 1
Question 2
Question 3
Question 4
Question 5
Total
Problem 1 (10 Points).
Circle TRUE or FALSE for each of the following statements about static variables in Java.
TRUE FALSE
B. A static data member of a class is not associated with any particular instance of the class.
TRUE FALSE
TRUE FALSE
TRUE FALSE
TRUE FALSE
Problem 2 (8 Points).
public Borg() {
/* assign unique id */
XXX
}
}
We want to give each Borg object a unique identifier. Which of the following lines could
be used in place of the XXX to assign a unique id to each Borg object?
(Circle only ONE choice)
a) nextID = borgID++;
b) borgID += 1;
c) borgID = nextID + 1;
d) borgID = ++nextID;
e) borgID += nextID;
Problem 3 (45 Points).
The following main method uses the functions print and add to produce this output:
Output:
Array a is:
1
3
5
Array b is:
7
8
3
Array c is:
8
11
8
Main Method:
Provide implementations for print and add so that the main method produces the correct
output (see next page).
A. Write code for correctly printing a single array.
B. Write code for adding the elements of two int arrays. The result should be returned as a
new array: Assume that the arrays, a and b, have the same number of elements.
When writing these functions remember that the output of main must match:
Array a is:
1
3
5
Array b is:
7
8
3
Array c is:
8
11
8
Problem 4 (25 Points).
Here is a class that has two instance fields: type and weight.
// rest of class
}
Provide a constructor for this class. This constructor should take two arguments: a String
and a double. This will allow a programmer to create a new Cookie object with parameters
like Chocolate and 2.9
Provide another constructor for this class. This constructor should take a single String as an
argument. This will allow a programmer to create a new Cookie object with a parameter like
Chocolate. When no weight is provided, the Cookie should weigh 2 grams.
public Cookie(String ctype) {
type = ctype;
weight = 2.0;
}
Problem 5 (12 Points).
System.exit(0);
}
}
class UserAccount {
public String username;
private String password;
Consider the program above, which consists of two classes that are contained in the same
file. Circle TRUE or FALSE for the following statements.
TRUE FALSE
TRUE FALSE
8c. The line at C will compile and run.
TRUE FALSE
TRUE FALSE
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.