Lab 3: Algorithms in Java

The goal of this lab is to practice writing, compiling, and testing Java programs.

Make a new directory, and copy the file Lab3.java from the course directory.

cp /homeemp/tvandrun/pub/235/Lab3.java .

This file gives you five of the algorithms problems we saw at the beginning of this class several weeks ago. We solved these algorithms before; now you must write them in Java and make working programs out of them.

Using if and while is new to you. Look on the board to see how to form these correctly in Java. There also are parts of the program given to you that you will not yet understand.

Uncomment each program as you go along. Make sure you document your variables.

Turn-in

  1. Start a script. Remember this is done using the script command, giving the name of a script file.
  2. Delete any class files. This is done using the rm command. rm *.class will delete all files that end in .class. Be careful--- don't delete your .java files!
  3. Print the file
  4. Compile the program, as you did before.
  5. Run the program, as you did above.
  6. Exit the script.
  7. Print the script. I recommend using a2ps -P sp (name of script file). a2ps prints the file in "2-up" mode. Remember that sp is the name of the printer.

Make sure you have exited the script file before you print, or else it will print forever!

Then turn in the hard copy to me.


Thomas VanDrunen
Last modified: Mon Sep 4 10:00:27 CDT 2006