CSE 115 - Spring 2008 - Banner
   CSE 115 - Spring 2008 - Introduction to Computer Science for Majors I
CSE 115 - Spring 2008 - Navigation CSE 115 - Spring 2008 - Lab 2

Lab 3

Introduction

We are still learning some of the basic components of a Java file, but we have seen one very important idea - relationships! Relationships between classes will allow us the ability to have classes work together in some way. Before we have too many classes in our projects to count, we will focus on some simpler ideas and eventually put them all together to build some pretty cool stuff..


Objectives

The high-level objectives of this lab are to have you,
  • use Green to help you create relationships between classes
  • create variables inside of your code so you can refer to the same object repeatedly
The following are the new concepts covered in this lab:
  • using Green to create relationships
  • creating local variables
  • using local variables to communicate with objects multiple times

Helpful Hints

Read through the entire lab before you start working, so that you know what to expect. Make sure you save your work often, and keep track of what you are expected to submit.

Unless you have a fabulous photographic memory, you should expect to have to look back at previous labs if you do not remember how to do certain things.


Reading

Make sure you have read chapter 3 of the book before coming to lab. Also make sure you have reviewed your lecture notes.


Lab set-up tasks

At your lab session your teaching assistant will briefly discuss how to carry out each of the set-up tasks below. She or he will also be available to answer questions you might have.

These are things that you must do that you learned how to do in previous labs. If you don't remember how to do any of these tasks, refer to Lab 1.

Step 1: Log in

Step 2: Open Eclipse

Step 3: Make sure you have the DrJava interactions pane visible

Step 4: Make sure you can see the connections to the code repositories

These are things that you must do that you learned how to do in previous labs. If you don't remember how to do any of these tasks, refer to Lab 2.

Step 5: Check out Lab3 project from LabSkeletons repository


Lab Assignment (To be completed in Lab and checked by TA for attendance)

In the DrJava interactions pane you will duplicate some of the code that was demonstrated in class. To get full credit for this exercise, you should do the following:

1) Create a chapter1.Terrarium

2) Add two or more chapter1.Ant objects to the terrarium and tell some of the ants you created to start().

Once you have completed this task, leave the Terrarium window running and then ask your TA to come over and view your interactions pane and the Terrarium winodw. The TA will be giving you credit for completing this part of the assignment, thereby giving you credit for attendance in lab this week.


Lab Assignment (To be completed and submitted - can be finished in lab or may have to be finished outside of lab time)

Use the Dr. Java interactions pane to test out your ideas for the creation of the final program. In the lab3lib package, there is another set of classes that function similarly to the Ant and Terrarium. They are called the BouncingWorld and the BouncingBall. You can create a BouncingWorld and then add BouncingBalls to it. You should do this first in the Dr. Java interactions pane.

After you have put at least one BouncingBall into the BouncingWorld, take note of the fact that the BouncingBall has a few capabilities that we can invoke upon it. We can change its color, its size, or its pattern of movement. If you did not create a local variable for a BouncingBall before, do so now and create another BouncingBall. Pick one of these things to change about the ball and watch the results. Now, pick another and watch the changes. You can find out more information about these capabilities by consulting the JavaDocs for the BouncingBall class located here.

After you feel confident in working with the BouncingBall, continue on to complete the part of the lab which you are to hand in.

You will fill in the code for the class MyBouncingBallWorld so that it show the following relationships. There is a local variable dependency between MyBouncingBallWorld and lab3lib.BouncingBallWorld, as well as at least one local variable dependency between MyBouncingBallWorld and lab3lib.BouncingBall. There must also be at least one instantiation dependency relationship between MyBouncingBallWorld and lab3lib.BouncingBall. You must change at least one of the properties of one of the balls you create. You will illustrate your use of the relationships using a UML class diagram.

Using Green to Create Relationships

Open the package lab3 in the Green editor in a new class diagram. You should see the class MyBouncingBallWorld appear in the diagram. Next, you should add the class boxes for the lab3lib.BouncingBallWorld and lab3lib.BouncingBall to the diagram. These classes already exist, so instead of selecting the Class button from the palette, you should expand the Referenced Libraries entry in the project and expand the Classlibs.jar entry. Find the package lab3lib and expand that as well. Select one of the classes you need to add to the diagram and select to add it to the last viewed class diagram. You can add the other class in a similar way. Now, you can use the palette to select the relationship you are interested in and click on the first class of the relationship as well as the second.

Finish the Code for MyBouncingBallWorld

You should now make sure that the code you wrote meets the specifications given above. In order to see that your world looks the way you want, you can simply create an instance of it using the DrJava Interactions pane.


What you hand in

When you are finished, you need to export your solution from the Eclipse environment so that you can submit it. Follow the steps described in Lab 2 to do this. Your submission must contain your completed MyBouncingBallWorld as well as a UML diagram named Lab3.grn.

Now you can submit the resulting jar file, Lab3.jar. If you do not remember how to do this, refer back to the instructions in Lab 2.


Due dates

The due dates for the lab are summarized below.

To check that your lab was submitted, you can always refer back to the Submit Inspector on the Resources page of the website. After you have entered your user name, your submissions will be shown.

Date of lab Due date for electronic submission
Tuesday, February 5 Monday, February 11
Wednesday, February 6 Tuesday, February 12
Thursday, February 7 Wednesday, February 13
Friday, February 8 Thursday, February 14

 

CSE 115 - Spring 2008 - Footer

 

 
Page Maintained by: Adrienne Decker