Lab Assignment 4
CS202,
Summer 2006
Please upload your source code files using CSNS.
Note that file
uploading will be disabled automatically after the lab ends, so please
turn in your work on time.
1.(10pt) Come up with an example to show that the default access
modifier
(i.e. no access modifier is specified) is not public, private,
or protected.
2. Class hierarchy of Document
- (5pt) Create a class Document
that contains a member variable text
of type String, which stores
any textual content for the document. Create a method toString
that returns the text field.
- (5pt) Create a class Email
that inherits from Document
and
includes member variables for the subject,
sender, and recipient of an
email message. The
body of a email message should be stored in the inherited variable
text. Override the toString method to concatenate all
text fields.
- (5pt) Create a class TextFile
that inherits from Document
and
includes a member variable pathname.
The textual contents of
the file should be stored in the inherited variable text. Override
toString method to
concatenate all text fields.
All the member variables in the classes must be private. You may create any
constructors, and getter/setter methods if necessary.
- (5pt) Write a DocumentTest
program to test the classes you created. The program should create
several sample objects of type Email
and TextFile, read a keyword
from console input, and output the objects that contain the keyword.
For example:
if( obj.toString().indexOf(keyword)
>= 0 ) System.out.println( obj );
3.(10pt) Implement a class CDAccount which inherits from the
Account class.
A CD account has the restriction that a transaction (deposit, withdraw,
or transfer) can only occur during the one week grace period after an
account matures. For simplicity, we assume that all CD accounts have
the same 30-day term. Also for this exercise, you do not need to
implement the transfer method.
HINT: to calculate the difference between two dates, you may
consider using the getTimeInMillis()
method in the Calendar
class.
getTimeInMillis() returns the
current time in milliseconds since
January 1, 1970.