Comp101 Lab 2


In this lab you will do your first actual java programming, creating objects and calling methods. You will contine to get used to the Unix computing environment. A considerable part of this lab is spent in getting used to the tools you will use to write and build your program.


Assignment Specifications

In this lab you will take preexisting files and finish them to create a  flag of the Bahamas. (I know the colors are a little off, but you get the idea). When you are finished, your program should look like this when you run it:


Copying the files

First you'll need to copy the starter files over to your directory.
cp /home/bscstaff/jsantore/ .
and then unzip the files
This has created a folder called Lab2 in your home folder. Make the Lab2 folder your working folder (using the cd command appropriately as you learned in the last lab) Then see what files are there using the ls command.

Start using xemacs

This section is best done either on campus, or from a genuine highspeed connection (not the cable modem that is heavily used by everyone else on the street, or the lowest speed dsl)

One of the files that you just unzipped is named This is the file that you will need to work on. So open this file using xemacs. First make sure you are working in the Lab2 folder from your command line. From the command line type:

emacs &

This may take a few seconds to come up fully. There is some configuration for using java that gets done when starting emacs. From off campus emacs may take as long as a minute to startup. You should see something like the following:
xemacs with open

You see that the file is nicely "pretty printed" with comments in blue, java keywords in a a sort of pale purple and so on. xemacs will also help you to indent your code later on when you are writing more extensive programs.

The program runs as it is, it just doesn't do very much. Before we can run any program,  we must compile it. 

To compile, go back to your command line and type:

javac *.java

recall that this wild card will match all files with a .java suffix in your current directory. So this command will compile all of the java files in your directory.

Running the program.

Now lets run your program. We run a program in java by using the command java and then the name of the class with the main method in it. In our case

java Lab2 &

You may get a warning about a font, this is only a warning and the font will just look a little ugly. After running the program you will see a nice gray window like the one below:
initial look of the window

Congradulations, you are now ready to begin writing your part of the program.

Writing Java code.

In order to make your Ganan flag appear, you must create three objects and call a method on each one. In the file, you will find two lines of comments that read:
//put your code below this comment

 //put your code above this comment

Put all of your java code between these two lines of comments.

You need to

When you have created the three objects and called show on each one, compile your program again, fix any errors in compiling and then run it again. If you see the complete flag from the first image above, you are done the program. Note that I've run into a Java bug occasionaly which forces you to minimize and then restore the window to see the flag sometimes.


To submit your program, zip up the entire Lab2 folder (as you zipped the lab1 folder last time) and submit using the online submission program that we used for lab 1

you can either use konqueror to zip the files or use the command below.

zip -r <your last name> Lab2

Refer to the last lab for a refresher on how to do this.

Due Date. 

This lab is due at 11:59pm on the day before class one week from now.