MIDTERM
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 11:00AM, and late turnin 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 midterm.txt or an
MS Word file midterm.doc. For
questions that could have multiple correct answers, giving one of the
correct answers is enough.
1.(15pt) Fill in the blank with a correct word to complete the
sentence:
(a) An object is called
if its value cannot be changed.
(b) A
instance variable can be accessed directly
by name within the same package or within a subclass.
(c) A method that calls itself is referred
to as a
method.
(d) All user-created classes in Java
implicitly inherit from the
class.
(e) Keyword
can be used as if it were a method name to
invoke a constructor of the same class.
2. (15pt) Use no more than three sentences to answer each of the
following questions:
(a) What is the difference between overloading and overriding?
(b) Why shouldn't we always make instance
variables public?
(c) Briefly explain polymorphism
and why it is useful.
[Programming]
3. Suppose you are contracted by a video rental store to development
a Java application to process video rentals. You have full freedom to
design the classes needed for this application, as long as they meet
the following requirements:
(a) (40pt) The classes must be able to store certain information
about
videos, customers, and rentals. In particular,
- A video has an id, a name, and a media type (e.g. DVD or
videotape).
- A customer has an id, a name, and a phone number.
- A video could be a "new release" or just a regular video. For new
releases, the rental fee is $2.99, and for regular videos, it's $1.99.
- The rental period is 7 days for the regular videos and 3
days for new releases. If a video is returned late, an $1/day late fee
will be charged.
(b) (25pt) The application must also include a program VideoManager.java
that allows an employee at the store to
- Check out a video by entering the id of the video and the id of a
customer. Note that the program should automatically record the date
when the video is checked out in order to calculate rental fees later.
- Check in a video by entering the id of the video. The program
should print out the total of the rental fee, which may include late
fee but exclude taxes.
You may use VideoManager.java as a
template for your program, and feel free to make any changes to it if
necessary. And for simplicity, you may also assume that the input is
always correct, e.g. the employee will not try to check out a video
that does not exist or has already been rented out.
4. (20pt) Write a Java program which performs the following two
operations:
- Reads weekend movie box office information from a text file. Each
line of the file consists of five fields: ranking, name, distributor,
weekend gross, and cumulative gross. The fields are delimited by
tab characters.
- Prompt the user to input an number, and output the names of the
movies whose weekend gross are higher than the given number.
Test your program with the file boxoffice.txt.
The total of the midterm is 100pt.
Anything above 100pt is considered extra credit.