The test is open-everything with the sole limitation that you
neither solicit nor give help while the exam is in progress.
Submit all answers on these exam sheets. No extra sheets are
allowed. If you are nervous about this, work out the problem on
a separate sheet and copy your answers here. You are required
to do problems 1-6 and one of 7 or 8. Please
write (in the grid below, in the obvious place) whether to want me to
grade problem 7 or 8. If you do not write in a 7 or 8, then you will
receive a zero for that part of the exam.
It is not likely that many people will finish this exam,
so work in such a fashion as to maximize your partial credit.
The purpose of the exam is to provide a means of assessment,
not to make you feel good. Better students will work
more efficiently and answer more questions. Sorry in advance
for any undue stress.
| Problem | You got | Out of |
| 1 | | 15 |
| 2 | | 15 |
| 3 | | 15 |
| 4 | | 15 |
| 5 | | 15 |
| 6 | | 15 |
| | | 10 |
| TOTAL | | 100 |
- Write an immutable
Person class for people that have only an integer-valued id,
a string valued name, and a birthdate, which is a java.util.Date.
None of these values can be null, and the name field must have
at least one non-space character in it.
- Add a method to the Polynomial
interface and ArrayPolynomial class from Homework 2 that multiplies
a polynomial by a real number. For example if you have the polynomial
3x2-9x+5 and you multiply it by -2, you would get back
the polynomial -6x2+18x-10. This method should return
a new polynomial.
- Write an enum class for
undergraduate grades at LMU: A, A-, B+, B, B-, C+, C, C-, D, F,
CR, NC, I, W, AU. Associate two properties with each grade: (1) the
number of grade points, and (2) whether or not the grade suffices
to give its recipient credit for the class in which the grade
was received.
- One of the freshman needed
to write a complex number class for homework, and found a "solution"
on the web that had a constructor taking in the real and imaginary
parts. The student got a bad grade, not for copying, but for being
insensitive to Electrical Engineers, who like to sometimes build
complex numbers from angles and magnitudes as well. Describe in
a few sentences what the freshman should have done, using words
like "static factory method" in your answer. Try to be complete.
- Write a Java method that
takes in an array of ints (called a) an int (called x), and an
object (called f) of a class that implements the following interface
interface Function {
int evaluate(int x, int y);
}
and returns the list obtained by applying f to x and each element of
the array in order. For example, if you had
int[] a = new int[]{5, 7, 6, 1};
Function subtract = new Function() {
int evaluate(int x, int y) {return x - y;}
};
and you called your method like this:
int[] b = collect(a, 2, subtract);
then your method should return the array [-3, -5, -4, 1].
- Draw a UML class diagram for basketball teams, their players
(and their positions), their coaches, their schedules
and their win-loss records.
- Assume someone has already
written an immutable Ellipse
class, with all fields private, a constructor taking in both radii,
and public methods to get the radii, the circumference, and
the area, and a toString method. Write an immutable class
called Circle that extends the ellipse class (to
leverage all the hard work that the ellipse class does)
but still feels like a circle for users of the new circle
class.
- Write a Java interface
for a robotic arm that controls a flame thrower. Be creative
but not too unrealistic. You may assume the existence
of classes named Point and Vector for 3-D positions and
directions, respectively.