CSE 115 - Fall 2006 - Banner
   CSE 115 - Fall 2006 - Introduction to Computer Science for Majors I
CSE 115 - Fall 2006 - Left Navigation CSE 115 - Fall 2006 - Lab 5

Lab 5

Introduction

The big lesson this past week was that we can name objects using instance variables. Having a name for an object allows us to easily call methods on it many times.

We have also learned about the composition relationship.

In this lab you will have an opportunity to implement these relationships in code.


Objectives

The high-level objectives of this lab are to have you,
  • declare instance variables
  • call methods on objects using an instance variable
  • express the realization relationship in code (i.e. you will write a class which implements a given relationship)
  • express the composition relationship in code (i.e. you will write a class which uses another class)
  • learn how to create and edit a class diagram using the UML class diagram tool green
The following are the new concepts covered in this lab:
  • composition
  • realization
  • declaring instance variables
  • defining methods
  • calling methods

Assignment Specifications

Grouping is an important idea. We group together similar things and treat them as a whole to enable us to effectively deal with large numbers of individual entities. For example, Bart Simpson can talk about his mother, Marge, his father, Homer, and his sisters Lisa and Maggie. But sometimes it makes more sense for him to just talk about his family. The notion of family is more abstract (and therefore simpler) than the individuals which make up a particular family (like Marge, Homer, Lisa and Maggie). Similarly it is easy to talk about the Brady family (from the Brady Bunch, if you remember that show or have seen the recent movie), but a bit harder to remember that it is made up of Carol, Greg, Maria, Peter, Mike, Jan, Bobby and Cindy.

Moreover, I can talk about my family without you knowing specifically who is in my family. If the exact membership of the grouping isn't important, then you and I can have a perfectly good conversation about "things we do with our respective families", like have cookouts, go to the movies, watch the game on the weekend, and so on.

The same thing goes for software. It is often the case that one part of a software program needs to communicate with a group of other components of the same program, and have them all do the same thing, but it isn't really important how many components are in the group.

We saw in class how we can build an object which serves a grouping function. In this lab you will do the same - you will build various groups of objects. The objects are shapes: we are providing you with three shapes:

  • lab5lib.Oval
  • lab5lib.Rectangle
  • lab5lib.Triangle

In this lab you will work with a framework that we have built for you. The framework consists of an Applet with two drawing canvases, each with a set of buttons. Each drawing panel has the three buttons, labelled "Random Color", "Speed Up" and "Slow Down".

If a shape is placed into one of the two drawing canvases, it can be hooked up to the corresponding set of buttons - which means that if you click any of that set of buttons, then the shape will be affected (its color will change, it will speed up or slow down, depending on which button you click).

How do you add a shape to a drawing canvas? Here the framework takes over some of the hard work. The framework makes sure that all of the shapes that you create, until you hook up one shape to the buttons, are attached to the left drawing canvas. All the shapes you create after that end up in the right drawing canvas, until you hook up one shape to the right set of buttons. After you do this, you can add no more shapes to any drawing canvas.

How do you hook up a shape to the buttons? If you have an instance of the class lab5lib.ButtonGroup, you can call the setCurrentButtonGroupTarget method, which requires that an object of type IMovingShape be passed along as an actual argument.

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.

Do not be afraid to refer to earlier labs to recall what things mean or what commands are available for you to use.


Reading

Make sure you have read to the end of the composition section of chapter 4 before coming to lab. Also make sure you have reviewed your lecture notes.


Lab set-up tasks (If you are working at home see these directions for this lab)

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. Before you start work on the lab itself, you must carry out each of the following set-up tasks. Your teaching assistant will guide you through this process. Refer back to other lab assignments if you do not remember how to complete these tasks.

Step 1: Log in

Step 2: Start Eclipse

Step 3: Check out Lab5 project from LabSkeletons repository

Step 3(a): Note that this lab skeleton has two sub-packages! You are to do each part of the lab in a separate sub-package.

Step 4: Do the required lab work (instructions below)

Step 4(a): Put the code for part 1 into the lab5.part1 package.
Step 4(b): Put the code for part 2 into the lab5.part2 package.

Step 5: When finished, export your project and submit it (instructions below)


Lab Design

Once again, the TAs will help you to develop the appropriate class diagram for this assignment in recitation. Your submitted lab must implement the UML class diagram discussed in recitation. When running this lab, you must create four run configurations, one for each part of the lab. In each, set the size of the AppletViewer window to 800 pixels wide by 400 pixels tall. If you do not remember how to do this, refer back to Lab 3. The TAs can show you how to duplicate an existing run configuration and modify it so that it will run the Applet of a different sub-package, and also how to rename the run configuration.

You should be sure to check out all of the Javadocs for the Classlibs.jar, located here.

Build up the Code Incrementally

As we have said in the last several labs, it is important to build your code in small stages until you get to the finished product.  This is even more important now that your labwork is becoming a bit more substantial. You should write the part of the code so that Applet uses a Lab5System first, then run it. Next, create one group, and add it to the Lab5System. Fix any syntax errors that exist. Once the syntax errors are fixed, run your code to make sure it functions correctly. Continue in this manner (add a little bit of code, run it and test it) until you have completed the required lab tasks.

Part 1

In this part, your job is to implement the design shown in the UML class diagram below. We will guide you through the implementation of this design in part 1, step by step. In part 2 we will give you a diagram but less guidance: you will need to follow the same approach in part 2 as we show you in part 1. Make sure you put your code for this part in the pab5.part1 package.

So where do you start? Start with setting up the instantiation dependency between Applet and Lab5System classes. If you don't recall how to implement the instantiation dependency relationship between two classes, review your notes and previous lab work.

Next, set up the relationship between Lab5System and the Triangle class. Run and test. This should result in a triangle bouncing around in the left drawing panel. It will look something like this:

Next, create the class TwoTriangles in the package lab5.part1. Notice that this class is to implement the lab5lib.IMovingShape interface. This means that you will need to implement the methods specified in this interface.

Hmm. This sounds like a lot of work to do all at once. Let's break this down into more manageable chunks.

First create a stubbed out version of TwoTriangles, and hook it up to the buttons. Compile and run. Of course, since there are no shapes the class, clicking the buttons will have no effect.

Next set up one composition relationship between TwoTriangles and lab5lib.Triangle. Call the instance variable _triangle1. Compile and run. At this point the buttons will still not have any effect, because the buttons call the interface methods, which are currently stubbed out.

The next step is to define one of the methods. Let's do slowDown first. The way to define this method is to call the slowDown method on the _triangle1 object:


public void slowDown() {
    _triangle1.slowDown();
}

Compile and run. Now, clicking the "Slow Down" button on the right should cause the triangle on the right to slow down.

Do the same sort of thing for the other two methods, making note of the fact that the setColor method has a parameter. Compile and run, testing the two remaining buttons.

Finally, add the second composition relationship between TwoTriangles and lab5lib.Triangle. Note that you need to update each of the method definitions so that they call the relevant method on both the triangles.

You must use Green to produce a UML class diagram of the lab5.part1 package and all of its related classes, as in the picture given above. Be sure to save this file as Part1.dia in your workspace, and be sure to include this file when you export your solution to hand in.

To get Green working, you will need to follow the directions below.

Step 1: Make local plug-ins available

To do this, go to "Help" -> "Software Updates" -> "Manage Configuration".

This will open up the "Product Configuration" window.

Select "Add an Extension Location" from the right-hand window. You will see the following window:

Click on "Filesystem" in the left-hand pane and browse to /projects/CSE115/eclipse

Once you've done this, click "OK". After you click "OK" Eclipse will ask whether to restart the workbench:

Click "Yes" to restart the workbench. When you do, your Eclipse window will disappear for a little while, then Eclipse will start up again.

 

Part 2

In this part, your job is to implement the design shown in the UML class diagram below. Make sure you put your code for this part in the lab5.part2 package.

When you build your MixUpThree class, be sure that this grouping contains exactly one instance of each type of shape. Also be sure that it is hooked up appropriately to the buttons, and that each button affects all the shapes in the group.

When you build your MixUpFive class, be sure that this grouping contains at least one instance of each type of shape, and that it contains exactly five shpae instances in all. The exact mix of shapes is not important. Also be sure that it is hooked up appropriately to the buttons, and that each button affects all the shapes in the group.

You must use Green to produce a UML class diagram of the lab5.part2 package and all of its related classes, as in the picture given above. Be sure to save this file as Part2.dia in your workspace, and be sure to include this file when you export your solution to hand in..

Note that in part 2, unlike part 1, you may use Green to draw part of the diagram, such as the composition relationships. The TA will help you use Green. Make sure your export includes both the Java source files and screenshots.


What you hand in

When you are finished, you need to export your solution from the Eclipse environment so that you can submit it. You need to follow the same steps as you did for disconnecting from the repository in Lab 2. If you are not sure how to do this, please refer back to those instructions. This time, you should name your Jar file Lab5.jar.

Then you can submit the Lab5.jar file using the electronic submission program. If you do not remember how to use the the submission program, refer back to earlier labs.


Due dates

You have one week from the meeting of your lab to submit your solution.  The due dates are summarized in the table below. You are always welcome to submit early. If you submit more than once, the later submission will simply overwrite the previous one.

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. Clicking on the name of a file that is a zip file will show you the contents of the zip file so you can verify that you indeed zipped up all the correct files.

Date of lab Due date for electronic submission
Wednesday, October 4 Tuesday, October 10
Thursday, October 5 Wednesday, October 11
Friday, October 6 Thursday, October 12 19
Tuesday, October 10 Monday, October 16 19

 

CSE 115 - Fall 2006 - Footer

 

 
Last modified: Wed Oct 4 08:35:35 2006