Assignment 1 (First session): Initial reading and programming assignment
Reading. Please chapters 1 (through page 50), 2, and 3 of Eckel.
Programming. Please do the following exercises. Please hand these
exercises in, finished or incomplete, by 29 September (by either mailing me
source code or pointing me at a URL). You can work on these problems past
the 29th, but I'd like at least to see where you are at that point.
TIJ, Ch. 2, ex. 1.
Revise TIJ, Ch. 2, ex. 1 so that the print statement (the
call to System.out.println()) occurs in some method other than main().
You'll want to be sure you understand the discussion of "static" at
pp. 117-119.
Optional. Write a Java class that prints "hello, world",
and the body of whose main() method looks like this:
Reading. Please read chapters 4 and 5 of Eckel. In chapter 4, it's
not really necessary to read the sections on finalization and garbage
collection, pp. 207-19.
Programming. Please do the following exercises. These are due by
October 13th, in the same form and on the same terms as the first set
of exercises
TIJ, Ch. 4, ex. 1. Using a static data member in your class,
let the message that's printed read "Hi, I'm the Nth instance of this
class to be created" (where N increments over the course of the program
using your class).
TIJ, Ch. 4, ex. 10, amended as follows: "Create a class with
two (overloaded) constructors. Let the class be called BallOfTwine,
and let it have one data member of type double called diameter and one
data member of type String called color, the job of the constructors
being to initialize these members. The first constructor should accept
one parameter of type double. The second constructor should accept two
parameters, one of type double and one of type String. Using this,
call the second constructor inside the first one (passing along
the double value it received and also a reasonable default String value).
TIJ, Ch. 4, ex. 19.
TIJ, Ch. 5, ex. 11, with the amendment that all the classes
should belong to an explicitly named package.
Assignment 3 (Third session)
Reading. Please read chapters 6 and 7 of Eckel, on inheritance and
polymorphism.
Programming. The following problem set is due November 4th (which falls
on a between-sessions weekend). The problems involve pretty straightforward
issues in the areas of composition, inheritance, and polymorphism. If you
find ambiguities or run into difficulty on specific points, that number
again: w-i-k-i (or mail).
"Composition" exercise. Dredge up a definition of the two-dimensional
Point class from the session notes. Write an equals() method for Point
that tests the equality of Point instances in terms of the equality of
the coordinate values stored in them. Define a class LineSegment that has as data
members two Point instances. Write two constructors for LineSegment: one
that takes four integer arguments (two pairs of x and y coordinates), and
creates Point instances and initializes them appropriately; and a second
one that takes two existing Point instances as arguments. Write an equals()
method for LineSegment that uses the equals() method you defined for Point.
TIJ, Ch. 6, ex. 8.
TIJ, Ch. 7, ex. 6.
TIJ, Ch. 7, ex. 12.
Optionally, extend the Point/LineSegment problem as follows:
Extend Point to cover three-dimensional points by defining a class Point3D
(with appropriate constructors, an equals() method, a toString() method,
etc.). Make any adjustments in LineSegment that you think are appropriate.
Assignment 4
Reading. The reading assignment for the interval between sessions 6 and
7 will be chapters 13 ("Creating Windows and Applets") and 14 ("Multiple
Threads"). Because some of you may not have usable
graphics programming environments at this point, I'm not going to mandate
any programming based on chapter 13.
Programming. This is the final problem set of the trimester. It's due
December 12th, which is the Wednesday following the last weekend of classes.
TIJ, Ch. 11, ex. 5, amended as follows: "Open a text file so
that you can read the file one line at a time. Read each line and
compare it to a set of search terms specified on the command line. Print any
lines in which any of the search terms appear. N.b. the command line search
terms are available to your program via the String array that's the
parameter to main().
Optionally, adapt the object serialization code from the
IPL notes for November 9th and the TCP client/server code from the IT
notes for October 26th to move String objects between a network client
and a network server.
TIJ, Ch. 12, ex. 6, amended as follows: "Write a method that
takes an object as a parameter and recursively prints all the classes in
that object's hierarchy, i.e., all the classes between the immediate class
of the object and java.lang.Object." Please also do TIJ, Ch. 12,
ex. 14.
Optionally, write a method that takes two objects as parameters
and returns a Class instance representing their nearest common ancestral
class (if they share one, other than java.lang.Object) or null (if they
don't).
Optionally, any of the exercises from TIJ, chapter
13 (ex. 6, for example, looks reasonable).