Java logo

CS I/II in Java™

HOMEWORK ASSIGNMENTS


FALL 2001


Assignment 1 (due September 5, 2001): CLICK HERE!
Assignment 2 (due September 12, 2001): CLICK HERE!
Assignment 3 (due September 19, 2001): CLICK HERE! Give to T.A. or secretary since no class that day.
Time for some easy ones!

Assignment 4 (due September 24, 2001): Exercise 4.25 from the text.
Assignment 5 (due September 26, 2001): Exercise 5.9 from the text.
Now for a classic one!

Assignment 6 (due October 10, 2001): Exercise 6.37 (Towers of Hanoi) from the text. Turn in a disk (with labels both externally and internally) containing a batch file called run.bat in the top directory so I can easily see it work. It may be an application or an applet this way and I don't have to care. Prompt for the number of disks (with the understanding that a large number of disks takes too long). You should time the program and also keep a count of the number of recursive calls your program used. Print these statistics out at the end.
Now for a fun (but not trivial) semi-graphical one!

Assignment 7 (due October 17, 2001): Exercise 7.21 (Turtle Graphics) from the text. Turn in a disk (with labels both externally and internally) containing a batch file called run.bat in the top directory so I can easily see it work. It may be an application or an applet this way and I don't have to care which. You may use the system of input described or letters like "U" for up and "D" for down. If you want input from the user, prompt for it with adequate information.
Now for another easy but long one.

Assignment 8 (due October 29, 2001): Exercise 8.3 (Rational) from the text. Turn in a disk (with labels both externally and internally) containing a batch file called run.bat in the top directory so I can easily see it work. It may be an application or an applet this way and I don't have to care which.

By now it should be possible to have the "driver program" actually be a nice GUI. Buttons to add, subtract, multiply, and divide Rationals could be there. The display should be easy to read with simple input areas.
Now for an Object-Oriented one.

Assignment 9 (due November 19, 2001): Exercise 9.26 with all previous exercises needed concerning the Shape class hierarchy. Again, try to make the "driver program" look good.
Final Projects
Final Project 1 (due December 3, 2001): In class I passed out an exercise on the Flesch Readability Index. I have scanned it into the file Flesch.txt. For a small program which reads and writes to files, CLICK HERE! You may use this as a part of your program (although writing to a file is probably not necessary). Also, see the "handouts" for StringTokenizer information.
Final Project 2 (due December 10, 2001): Our Assignment 9 based on Shapes was quite easy. Now let's use the material in Chapter 11 on Graphics and Java2D to make it more interesting. Exercise 9.24 of our text asks for a basic graphics package. As usual, make the user interface as self-explanatory as possible.

SPRING 2002


Project 1 (due January 23, 2002): In order to get started, let's do Exercise 11.19 in our text. As usual, give me a disk (or CD-ROM) with a run.bat file in the top directory.

Project 2 (due January 30, 2002): Also in a review mode, let's do Exercise 11.33 or 11.34 in our text. That is, write either an application or an applet which takes any number of positive numbers and draws a pie chart with each piece a different color. You could use a non-positive number or a button to indicate the end of the input. As usual, give me a disk (or CD-ROM) with a run.bat file in the top directory. Allow me to input the data values (and prompt me for the end-of-file).

Project 3 (due February 4, 2002): Starting Chapter 12 and all the new GUI stuff; let's do Exercise 12.11 just for fun.

Project 4 (due February 11, 2002): Continuing Chapter 12 and all the new GUI stuff; let's do Exercises 12.27-12.31. Both mouse tracking and some drawing should be fun.

Project 5 (due February 20, 2002): Looking over Chapter 13 and all the GUI stuff, it's clear that there's a lot hidden in those paragraphs! I want to go on to Chapter 14 next week so let's finish up with one exercise from this one. Exercises 13.13-13.17 are enough. That means we won't practice some of the layouts but that's OK. Since 13.17 wants both applet and application, put that into your run.bat file.

Project 6 (due February 27, 2002): I have made available three examples of objects in the handouts. The first, Array, shows how to define a class of our own together with its data fields and methods. The second, Queue, shows how to extend the Array class and how to define additional methods for the class objects. The code there also shows how to write a sample test program for the class. The third, Vector, shows how to use a class which is built into Java and is made available by including the command: import java.util.Vector; (remember, you do not have to import pio.class, just have it in the same directory). The Vector class is sometimes more convenient than using Java's arrays which are always fixed in length once constructed. Note that I have included documentation on the class Vector at the end of the code in the handout.

The assignment is to construct a class called Stack which extends Vector and has the usual methods. For example, methods push(), pop(), top(), isEmpty(), isFull(), destroy(), size() are reasonable. You may wish to include a print() method for debugging purposes even though it would not usually be available to users.

Since the chapter we are finishing is about Exceptions, the assignment requires lots of exception handling! E.g., catch any attempt to pop from an empty stack. Since you can "destroy" a stack, you may also have to catch null pointer exceptions.

Write a good test program with a simple GUI which will allow the user to create and use stacks (buttons to push or pop, etc.). to show that your code works in many obvious cases.

Project 7 (due March 6, 2002): As a start on Threads, construct a digital clock. It should have buttons to start and stop it. A field for setting it would be nice. Of course the main idea is to do something that shows that you are using threads. If you want to copy some of Liang's sounds, that's OK too! SUN has some gong sounds in their demos if you want them.

Project 8 (due March 20, 2002): As a final threads program, Exercises 15.25, 15.26, and 15.28 are a start. At some stage you should write an applet which starts any number of colored balls off at random points with random directions at the click of a button. They should bounce correctly off the walls of the applet. Each should, perhaps, go faster and faster as time progresses so it becomes harder to "hit" them. With the mouse as a pointer, you can "hit" a ball and have it either disappear or blow up. (Can you make it noisy?) It might be interesting to have a special ball with higher priority which counts for extra credit (since it goes faster). It's not easy, but the balls should bounce off each other correctly (Physics course) if possible. How you keep score or add other features is up to you!

Project 9 (due April 3, 2002):
As a simple extension to the bouncing balls homework problem 8 (which gives you a chance to improve previous results), add buttons which save and restore the positions of the balls and their velocities. This is practice on using Files and Streams.

Project 10 (due April 17, 2002): As part of networking, it might be interesting to consider cryptography as an important consideration. We have a "Chat" system available now, how about writing a Public Key Encryption program which can be used to send "secret" messages. You might even want to use primes in the 200-300 range (I don't mean digits, just size). Publish your public key and encryption method but keep your private key secret. to yourself.

P.S., Everyone must be here bright and early, on time (which is 9:30am) on April 15th.