FINAL
CS202, Summer 2004
Please upload all your files using the turnin server
at the end of the exam. Note that you won't be able to upload any
file after 10:40AM. Before turn in any
program, try to
compile and run it and make sure it works 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.
1.(28pt) Fill in the blank with a correct word to complete the sentence:
- In order to handle action events, a class must implement
the
method in the
interface.
- All Java classes inherits from the
class, and one commonly used
method from this class is
.
- A
class cannot be inherited.
- The MouseListener interface has five methods. A mouse
event handler which does not want to implements all five methods should
inherits the adapter class
.
- Suppose your current working directory is c:\cs202\final,
and your code imports some classes from a package lab4.foo.
If the imported classes are under c:\cs202\lab4\foo, in order
to compile and run your program, directory
must be in the class path.
2. Give short answers to the following questions:
(a) (22pt) What are the similarity(s) and the difference(s)
between an interface and an abstract class?
(b) (10pt) Why polymorphism makes programming "easier"?
3. AddrBook implements a simple address book, where an
address
entry
consists of first name, last name, address, email, and phone number.
For this problem, modify the AddrBook
application (including AddrEntry.java if neccessary) as
follows:
(a) (15pt) Currently the address book only keeps one
address. Modify the code such that it can hold any number of
addresses.
(b) (15pt) Add event handling code such that the Next button
allows a user to cycle through all
entries in the
address book.
(c) (15pt) Add a Save menu item to the File menu. When
a user clicks on
Save, the application saves all entries in the address book to
the file
addresses.txt.
(d) (15pt) Add an Exit menu item to the File menu. When
a user clicks on
Exit, the application pops up a dialog box and asks the user
whether to save the addresses before exit. Based on the user's
response,
the application either exits, or saves the addresses then exits.
(e) (20pt) Add event handling code such that the Update button
allows a user to add a new entry
to the
address book, or updates an existing entry, based on whether there is
already an entry in the address book that has the same first name and
last name.