In
this lab you will use the Java you have learned in lecture to write a small
program.
1. Log in
2.
Start Eclipse
3. Switch to the CVS Repository Exploring perspective
4. Check out the SP2011-CSE115-Lab2 project from the Labs repository
5. Switch to the DrJava perspective
A. Do the following in the DrJava interactions pane,
declaring variables as needed. Once
you have finished, you must copy and paste the contents of the interactions
pane into the DrJavaInteractions.txt file contained in the lab2 package of the
src folder. BE SURE TO COPY AND
PASTE YOUR WORK BEFORE YOU CLOSE THE TERRARIUM WINDOW!
Create one
example1.Terrarium object, put one example1.Caterpillar objects, two
example1.Ant object and three example1.Butterfly objects inside it. Make the caterpillars, both ants and
one of the butterflies move by calling their respective "start()" methods. Let the ants, butterfly and caterpillars
move around for a few seconds, then call the "stop()" method on the ant,
butterfly and caterpillar objects you started earlier, but only on those.
Once you have
saved the contents of the interactions pane as described above, you should
close the Terrarium window. This
will reset the interactions pane, erasing whatever is there (which is why you
must save your work BEFORE closing the interactions pane).
B. Do the
following by writing Java code in the EcoSystem.java file from the lab2 package
using the Java editor.
First you
will do the same thing you just did in the interactions pane: you will create
some objects and call some methods on them. Edit the constructor definition to do the following: create
one example1.Terrarium object, put one example1.Caterpillar object, two
example1.Ant objects and three example1.Butterfly objects inside it. Make the caterpillars, both ants
and one of the butterflies move by calling their respective "start()" methods. Also call the "stop()" method on the
ant, butterfly and caterpillar objects you started earlier, but only on those.
Make sure you
save your changes. In the
Dr Java interactions pane, create an instance of lab2.EcoSystem. What happens? Can you explain?
Remove the calls to "stop()" from the code in your EcoSystem
constructor. Save your changes,
and try things out in the interactions pane again.
Answer the following question (briefly) in the Explanation.txt file contained in the lab2 package of the src folder of the Lab 2 project.
What could you do to get the insects (catepillars, ants, etc.) to stop after a certain time when the program was running? You may not actually know how to write the code for this and that is fine. Explain "in English" the code you would like to write. (Note: There are actually many different answers and many different ways this could be achieved in programs, but you only need to discuss one way.)
In the DrJava
perspective you should see the PackageExplorer view on the left of your
screen. Right-click on the project
name "SP2011-CSE115-Lab2" and drag down to "Submit...". Submit based on your official lab section.
If your submission
was successfully sent to the Web-CAT server, you will see a window which says,
"Your submission was successful."
Click "Finish" in this window.
If your submission was successfully
received by the Web-CAT server you
will see the following message displayed, "Your submission has been received by
the Web-CAT Grader and is being processed."
Otherwise you will
see a failure message. This means
your submission did NOT go through.
The most common problem is an incorrect password. If this is the case, you must attempt
your submission again.
Submission of Lab 2 is due the day before your recitation meets the week of February 14th. For your reference, consult the table below for due dates.
Recitation |
Lab 2 due |
---|---|
A1 |
Monday, February 14th at 9:00pm |
A2 & A5 |
Tuesday, February 15th at 9:00pm |
A3 & A6 |
Wednesday, February 16th at 9:00pm |
A4 |
Thursday, February 17th at 9:00pm |
Coming soon.
Lab authored by Carl Alphonce, Adrienne Decker