CSE115 Fall 2007 - Lab #3
Introduction
In order to successfully design and built large software systems we
need to manage their complexity. We will do this by designing systems
so that they are composed of small, independent parts with
well-defined responsibilities which interact with each other. These
small simple parts can be developed and tested independently of each
other. The complexity of the software system as a whole arises from
the interconnections and interactions amongst the component
pieces.
In lecture we discussed how to model systems of interacting
entities in terms of their properties (or characteristics) and
their capabilities (or the services they can offer to other
entities). The capabilities of objects determine how they can
communicate with each other. The relationships which a given
object has with other objects determines which objects it can
communicate with.
In lecture we explored one of the relationships which objects can
have with each other. In this lab we will focus in particular on the
instantiation dependency relationship. The instantiation
dependency relationship exists between two objects when one object
uses another object in some way. It is for this reason that the
relationship is sometimes called the uses a relationship. This
relationship can be expressed in Java by simply having one object
create a new instance of the other object.
We have spent this past week learning about methods and how to use
them to communicate with our objects.
Objectives
The high-level objectives of this lab are to have you,
- create instances of classes
- call methods on objects
- implement a design which is provided to you in the form of a UML diagram.
The following are the new concepts covered in this lab:
- calling methods
- passing parameters
- modeling the uses a relationship using object dependency
Assignment Specifications
In this lab you will work with classes which, when interacting in
the right way, allow you to display a bouncing shape of some sort in a
window. You have three kinds of bouncing shapes to choose from:
lab2lib.BouncingBall
lab2lib.BouncingSquare
lab2lib.BouncingTriangle
Each of these classes defines a no-argument constructor which you can
use to create an instance of the class.
The window is defined by a class named,
It also defines a no-argument constructor. Moreover, it defines a
method, named
addShape, which will add a shape to the
window's graphical display. Which shape is added? The one that is
passed as an argument to the
addShape method.
Note that we gloss over the type of the parameter of the
addShape method that is shown in the UML class diagram
below. It will be important later on to understand exactly what is
going on here, and the explanation will come soon in lecture. For
now, you can safely ignore the type of the parameter.
What you need to do
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 chapter 2 of the book
before coming to lab. Also make sure you have reviewed your
lecture notes.
Lab set-up tasks
Thursday lab students Make sure you do
lab 2 (aka lab 3 part I) before you do this lab.
If you don't, these instructions won't make sense!
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.
Step 1: Log in
Step 2: Start Eclipse
Step 3: Update your Lab3 project from the LabSkeletons repository
Right click on your "Lab3" project in your "Package Explorer" view.
Select "Team" -> "Update". This will retrieve the added files you
need for part II of lab 3 from the repository.
Lab Design
Now you're ready to start working on the lab itself!
It is important to come up with a design for your program prior to
writing it. The UML class diagrams introduced in lecture will help in
this endeavor and will be central to discussions throughout the
class. Right now we want you to understand how to take a UML class
diagram that includes the dependency (uses a) relationship and
generate Java code for that. Since it is still early in the semester,
we will help you create the UML that your lab must implement. As the
semester progresses, you will be responsible for coming up with your
own design for your projects.
Design #1
Open up the Lab3 project, and then the lab3.partII package.
Double-click on the Driver class in the Package Explorer. The Java
editor will open on the Driver.java file in the center
view. Notice that the Driver class has no statements in its constructor.
You must fill in the comments for modified by with your name. You should
make sure that your name appears in all the files that you write this semester.
In this first design, add statements in the constructor of the
Driver class so that a new lab3lib.Window is
created, and a new lab2lib.BouncingBall is added as a
shape to that window. The desired design in terms of dependency
relationships is:
To check that this is working properly, use DrJava to create an
instance of the
lab3.partII.Driver class. You should see a new
window open up, with a blue ball boucing around inside the window.
(Note: On styx you may need to manually resize the window to make it a
reasonable size.)
To check that your design is correct, open
lab3.partII.Driver in a new Green UML diagram. Click on
the name compartment of the class box, and type "i". You should get a
diagram that looks (except for layout differences) like the one above.
For later designs, perform the same check.
If this is working, move on. If not, call your TA over for
assistance.
Design #2
The next step is to add statements in the constructor of the
Driver class so that a new lab3lib.Window is
created, and a new lab2lib.BouncingSquare is added as a
shape to that window. The desired design in terms of dependency
relationships is now:
Notice the "cardinality annotation", the "2", on the relationship
between
lab3.partII.Driver and
lab3lib.Window. It indicates that
lab3.partII.Driver creates two instances of
lab3lib.Window. To check that this is working properly,
use DrJava to create an instance of the
lab3.partII.Driver class.
You should see two new windows open up, one with a blue ball boucing
around inside and one with green square bouncing around. Note: the
windows may open right on top of each other, so you may need to move
one aside to see the other one.
If this is working, move on. If not, call your TA over for
assistance.
Building the Code Incrementally
Notice that we are making you write a little bit of code, then test
it. Building a little of the code and testing it as you go is an
important habit to get into that will help you as the projects get
larger throughout the semester. This way, if there is a problem, you
discover it right away and it is easier to localize and fix.
Building code incrementally, in small steps, is in fact something
that professional software developers also do. It is well understood
that getting frequent feedback, after only small changes have been
made to a program, speed development.
Of coure the benefits of working incrementally extend beyond
writing software. Working methodically, one small step at a time, is
how most work gets done!
Design #3
The third step is to add statements in the constructor of the
Driver class so that a new lab3lib.Window is
created, and a new lab2lib.BouncingTriangle is added as a
shape to that window. The desired design in terms of dependency
relationships is now:
Notice the "cardinality annotation", the "3", on the relationship
between
lab3.partII.Driver and
lab3lib.Window. To check that this is working properly,
use DrJava to create an instance of the
lab3.partII.Driver class.
You should see three new windows open up, one with a blue ball boucing
around inside, one with green square bouncing around, and one with a
red triangle bouncing around. Note: the windows may open right on
top of each other, so you may need to move one aside to see the other
one.
If this is working, move on. If not, call your TA over for
assistance.
Design #4
The last step is to add statements in the constructor of the
Driver class to create a randomly chosen shape to yet
another new lab3lib.Window. The desired design in terms
of dependency relationships is now:
Notice the "cardinality annotation", the "4", on the relationship
between
lab3.partII.Driver and
lab3lib.Window.
The lab3lib.ShapeMaker class defines a method
randomShape which creates either a
lab2lib.BouncingBall, a
lab2lib.BouncingSquare, or a
lab2lib.BouncingTriangle, chosen at random, and
returns that object. Make use of this information to have a
randomly selected shape created in your fourth window each
time you create a lab3.partII.Driver.
To check that this is working properly, use DrJava to create an
instance of the lab3.partII.Driver class. You should see
four new windows open up, one with a blue ball boucing around inside,
one with green square bouncing around, one with a red triangle
bouncing around, and one with a randomly chosen shape bouncing around.
You should run this a few times to make sure that the fourth window
does contain different shapes from time to time. Note: the windows
may open right on top of each other, so you may need to move one aside
to see the other one.
If this is working, move on. If not, call your TA over for
assistance.
What you hand in
When you are finished, you need to export your solution from the
Eclipse environment so that you can submit it. Check that the file you
produced in lab last week, "PartIExplanation.txt", is in your Lab3
project. If not, make sure you put it there.
You should now disconnect your completed project from the CVS
repository from which you checked out the lab skeleton. To do this,
right click on the project name, and select "Team" -> "Disconnect". In
the "Confirm Disconnect from CVS" window that pops open select "Also
delete the CVS meta information from the file system.", then click
"Yes":
Now it is time to package up your completed work to get it ready
for submission. Right click on the project name, and select
"Export...". An "Export" window will open. Under Java, select "JAR
file":

Click "Next>". This brings up a new screen, which will look
something like the one pictured below (but yours will, for
example, make reference to "Lab3" rather than "Lab2".
VERY IMPORTANT: MAKE SURE THAT THERE IS A
CHECK IN THE BOX NEXT TO THE OPTION FOR EXPORT JAVA SOURCE FILES AND
RESOURCES!!!!
To pick a name for the file you are exporting to, click the "Browse"
button next to the field labelled "JAR file:".
Name your file "Lab3.jar", then click "Finish".
Now you can submit the resulting jar file, Lab3.jar. This
file should be in your home directory. To submit, you use the
electronic submission program that corresponds to your recitation.
For instance students in section A1 will submit by typing
submit_cse115a1 Lab3.jar
at the Unix prompt.
If when you try to submit you get a message stating
"submit_cse115XX: Command not found." then you need
to add the following line to your .cshrc file:
set path = ($path /util/bin)
And then type the same command at the prompt. The changes to your
.cshrc will take effect the next time you log on.
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 use the Submit
Inspector on the Resources page of the website. After you have entered
your username, 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 |
| Tuesday, September 18 |
Monday, September 24 |
| Wednesday, September 19 |
Tuesday, September 25 |
| Thursday, September 20 |
Wednesday, September 26 |
| Friday, September 21 |
Thursday, September 27 |