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 bouncing ball in a window.  When you are finished, your program should look like this when you run it:
static view of what lab 2 should look like when you are done.

Getting Started:

Copying the files

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

xemacs is best used either on campus, or from a genuine highspeed connection (not the cable modem that is heavily used by everyone else on the street)

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. From the command line type:

xemacs &

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 showing the file to edit.

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. Emacs will also help you to indent your code later on when you are writing more extensive programs.

This file happens to be the main file for your application. You'll see the "public static void main(String[] args)" which your book correctly tells you that any application program must have. 

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

Right now the java interface with xemacs is not working well. So go back to your command line. (making sure you are in the Lab2 directory) and type
javac *.java

to complile all the java files in the directory. You can also put a specific java file on the command such as


if you only want to try compiling one file at a time.

Running the program.

Once again, the jde menu has some problems on this system right now (I've got a ticket in with the IT folks), so I reccomend the following. Go to your command window (the one you ran emacs from) and run the program directly.
java Lab2

when you run a java application, you use the java command and the name of the class which contains that funny public static void main method. In our case that is the Lab2 class.

When you first run the program without doing anything, you will see that you get your command prompt back after about a second without the computer doing anything. thats ok, you need to write the program now.

Later on when you run the program and it shows the window,
You may get a warning about a font, this is only a warning and the font will just look a little ugly. 

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

Writing Java code.

In order to make your Bouncing ball appear, you must create a Bouncer object and call two methods on it. All of your code should be placed in the lab2Method() method of the Lab2 class. You will find two lines of comments that read:
    //put all of your code here in this method

    //the method end on the next line so you need your code above here.
Put all of your code between these two lines of comments.

You need to

When you have created the object and called the two methods on it, compile your program again, fix any errors in compiling and then run the program again. If you see the moving blue ball from the first image above, you are done the program.


To submit your program, zip up the entire lab2 folder (as you zipped the lab1 folder last time). Call your zip file
<your last name>

so for example I would need to name my zip file

If you don't remember you might try

zip -r <your last name> Lab2

Submit using the same proceedure as last time:

cd /home/bscstaff/jsantore/submission/g2/oss


Submit it outside of class on your own this time.

Due Date. 

This lab is due:
For the Monday/Wednesday class: Tuesday Oct 2nd at 11:59pm
For the Tuesday/Thursday class: Wednesday Oct 3rd at 11:59pm