Monthly Archives: August 2002

Computer Science 1

Dr. Steve Beaty’s Computer Science 1 class was my first class at Metro.  Beyond the standard things that make up an entry level CS1 class I was introduced to Java, Object Oriented programming, Javadoc, polymorphism, and refactoring.

Life Before Computer Science 1

Before CS1 I had some experience with Pascal running on the Alpha Micro in my high school programming classes.  I really liked the Alpha as it was a true multi user system.  My friend Eric and I spent hours reading through the system documentation and trying things out.  We discovered the fun of using the Force Job command to launch the “cookie monster” program on another users terminal.  It would interrupt whatever they were doing and ask for cookie.  As long as you typed in cookie you were safe.  Otherwise it would go nuts.

I have played with various flavors of Basic dating all the way back to 7th grade on Mr. Methvan’s Apple IIe with the Integer Basic card.  My buddy Jonathan and I keyed in the AWACS program from an issue of Creative Computing magazine and then spent months fixing it.  I also spent hours with my TI 99/4A.

Cereal Box Top Speech Synthesizer attached to TI 99 4A

1979 TI-99/4 with Speech Synthesizer, RF modulator, keyboard overlays

I saved box tops from breakfast cereal for months to get my speech synthesizer (the little box on right) – this thing rocked!  My friend Ricky and I spent hours getting the speech synth to swear. We would stay up late at night and make prank phone calls with it.  That was before caller ID of course.

As I write this I realize that I was a little prankster and I apologize to everyone for my juvenile behavior.

My first Java Program

Prank phone calls aside, Objects were something really new to me and so was Java.  I learned about class files, methods, polymorphism, and documenting code.

public class Main
    public static void main (String args[]) throws IOException

There it is, the basic Java program.  It compiles and runs and my First Program doesn’t do much more than that.

My first Java program

My first Java program

    public static void main (String args[]) throws IOException
        BufferedReader in = new BufferedReader
            (new InputStreamReader (;

        System.out.print ("Please enter a number: ");

        float f = Float.parseFloat (in.readLine());

        System.out.println (f + " Celsius = " + ((f*1.8)+32) + " Fahrenheit\n" + f + " Fahrenheit = " +((f-32)*0.555) + " Celsius");
        System.out.println (f + " Yards = " +(f*0.9) + " Meters\n" + f + " Meters = " +(f*1.1) + " Yards");
        System.out.println (f + " Liters = " + (f*1.06) + " Quarts\n" + f + " Quarts = " + (f*0.95) + " Liters");

Not bad for an introductory program.  Program input from the BufferedReader.  Program output to the screen. A little math and a primitive data type variable.  One thing I really did appreciate about Dr. Beaty though was that he didn’t do the hello world program.  He actually had us do something.  Every programing assignment introduced multiple concepts and techniques.


Dr. Beaty also handed us code that didn’t work and had us fix it.  His Padded String Class was one of these.  As the Padded String documentation shows this was a great example of overriding constructors.  This was my first lesson in polymorphism.

Constructor Summary

PaddedString(int w)
A constructor that takes only the width; this will pad with spaces and will do right alignment.

PaddedString(int w, char p)
A constructor that takes the width and a padding character; it will do right alignment.

PaddedString(int w, char p, int a)
A constructor that takes the width, a padding character, and an alignment.

PaddedString(int w, int a)
A constructor that takes the width and the alignment; the padding character will be a space.

Once we had the Padded String working we used it in our second assignment to format the output.

Padded String Formatting of metric conversions

Padded String Formatting of metric conversions

The PaddedString does different formatting based on how the object is instantiated.  This is polymorphism.  The PaddedString is a dog, but can be a St. Bernard, Grey Hound, or Poodle depending on how you create it.


My take away from CS1 was 2 fold. First – document, document, document.  I am nuts about it – maybe a little to nuts.  With the second assignment I was introduced to Javadoc.  I think I spent just about as much time writing doc comments in my code as I did writing code.  Dr. Beaty really encouraged doc comments.  It reminded me of the eSoft TBBS guys.  I listened to Phil Becker talk at BBSCON once about how they wrote the paper docs first and then wrote the code to match the documentation.  What a concept.  Dr. Beaty pushed us to do the same, doc first – code second.

Every class file, instance variable, method and any place where the code did something that wasn’t obvious requires comments.  The ADT’s and algorithms used require comments.  The expected behavior requires comments.  Variable passing, returns, he even encouraged documenting the errors that are thrown both by the program and the interpreter.


The second takeaway is also a truth for me.  A single method should never be more than about 66 lines of code – a single printed page.  Dr. Beaty said the mind cannot truly understand more than that.  If you have a method that is larger than that, perhaps it should be split up.  Every time I brought in some program that didn’t work for him to look at he would start with that advice.  9 times out of 10 after I cleaned things up the program would work.  I’m not stuck on 66 lines but I have found that if I can refactor something it tends to work better.  True refactoring though is about writing a new program that does exactly what the old program did, even the bugs.  I tend to use the techniques that Dr. Beaty taught us to split programs it into smaller chunks.  Re-working a block of code often cleans up the bugs.