FINAL
CS202,
Summer 2006
Please upload all your files and source code to CSNS
by the
end of the exam. Note
that file uploading will be disabled
automatically after 10:30AM, and late submissions will not
be accepted. Before
turn in your
programs, try to
compile and run them and make sure they work correctly. If your program
does not even compile, you receive an automatic 50% credit deduction
for that
problem, no matter how "close" the program seems to be correct.
[Q&A] For the following questions, please put your
answers in a
text file final.txt
or an
MS Word file final.doc.
For
questions that could have multiple correct answers, giving one of the
correct answers is enough.
1.(20pt) Fill in the blank with a correct word to complete the
sentence:
(a) Suppose your current working directory is f:\final,
and your code imports some classes from a package hw4.foobar.
If the imported classes are under d:\data\cs202\hw4\foobar, in
order
to compile and run your program, directory
must be in the class path.
(b) The default layout of a JFrame is
layout.
(c) In order to handle action events, a class must implement
the
method in the
interface.
(d) The MouseListener interface has five methods. A mouse
event handler class which does not want to implements all five methods
should
inherit from the adapter class
.
2. (30pt) Please give short answers to the following questions:
(a) Briefly explain why Java
distinguishes between textual data (handled by Reader/Writer classes) and binary
data (handled by InputStream/OutputStream
classes) in input and output.
(b) Briefly explain
how you used (or would have used in case you didn't complete the
assignment) inheritance and polymorphism in your CSPaint assignment and how they
helped to simplify the coding.
[Programming]
3. Quiz is a program that loads a quiz from
a text file, shows the
quiz to a user, lets the user to select an answer for each question,
then displays how many questions the user has answered correctly.
The format of the text file that contains the quiz is as follows:
- The file contains a number of problems,
and problems are separated
from each other by an empty line.
- A problem consists of
six lines: one line for the question
statement, four lines for four possible answers, and one line for the
label of the correct answer, which could be "a", "b", "c", or "d".
A sample quiz file can be found here.
Currently the Quiz program is only
partially implemented. In
particular, it can only load one problem from the quiz file. In this
exercise, you are going to complete the program by implementing the
following features:
(a) (20pt) Load all problems from the quiz file.
(b) (30pt) Use the Next
button to go through all the questions, record
the user's answer to each question, and displays the number of
questions that have been correctly answered at the end.
(c) (20pt) Add a Previous
button to let the user to go back to a
previous question. Note that the Previous
button should be disabled
when the first problem is displayed.
(d) (20pt) Add a Restart
button (along side of the Exit
button) that allows the user to redo the quiz.