Software Engineering: Analysis and Design ITECH 7201 Laboratory 1
Software Engineering: Analysis and Design ITECH 7201 Laboratory 1
ITECH 7201
Laboratory 1
Watch the video at the following link (if you haven’t done so already)
The idea is to find three things that help define that object (the way “size” and “colour” defined Apple in the
video).
There are a lot of different attributes you can choose for each and there is no real right or wrong answer. Just
pick three that you think are representative. Notice, what you have chosen does not really define the object –
it merely helps model a small part of that object.
The attributes should be designated as private and all of the methods should be public.
You can create the diagram with the following steps:
Open Enterprise Architect (EA) – there should be an icon on your desktop.
File -> New Project
o Save your project as lab1.eap somewhere safe on your filesystem (not the C: drive)
o In future you can open EA directly by double-clicking on the lab1.eap file
From the dialog that opens
o Ensure that Basic UML2 Technology is chosen in the Technology pane
o Check the class box in the name pane
In the Project Browser on the right of your screen
o Open the Class Model folder
o Double click on the Class Model diagram
o (if the Start Page is open you can close it)
The Class Model diagram will open in the central pane
o Select and delete any objects currently in this pane so that it is empty
o In the Toolbox on the right, click Class and drag onto the central pane
o In the dialog that opens, put the name of your class (eg Person) into the Name: text field
o Click Apply and then click OK
Adding Attributes
A small box will appear with the name of your class in the top section.
Right click on the class and select Attributes
Perform the following steps three times to add your attributes
o Click New
o Type in the name of your attribute (eg colour)
o Type in the name of the type of your attribute (eg String) –
note the basic types appear in the drop down box
o click Save
Adding methods
Right click on the class and select Operations (about half way down)
Perform the following steps 7 times to add 3 get methods, 3 set methods and a toString method
o Click New
o Give the method a name (eg setName)
o if the method has parameters put them in the Parameters box in the following format
type name, type name etc until all of them are added
set methods have one parameter
String colour (for example)
o Assign a return type
Set methods will be void
Get methods will have the type of their parameter
toString will have type String
Constructors are added in a similar way. However, they don’t have return types (being constructors).
o Open the Stereotype drop down box
o Choose constructor (near the bottom)
o Get rid of the return type
o All of the other steps remain the same
Make sure all of your methods are correct in the text box at the bottom.
If changes are needed
o click the relevant method
o Make the changes
o Click Save (always important)
When no more changes required
o Click Close
When you are happy with your diagrams, you will then make a class based on that diagram.
Open Eclipse
Make a new workspace if you wish for ITECH7201
Make a project for ITECH7201 classes
Make a package called Lab01
Make a Person class based on the class diagram on page 3.
Make a second class based on your other class diagram (eg a Car class).
Download the Test class from Moodle and add it to your lab01 package.
Optional/Challenge tasks
2. We (well I) have (clunkily) used a boolean variable for the gender and have arbitrarily decided that true means
female and false means male. The toString method will simply type out true and false for the gender, so anyone
not familiar with my code won’t know what is meant.
Add a private (why private?) method called assignGender to the Person class. This method should
return the String “Male” if gender is false, and “Female” if it is true. Use this new method in the
toString( ) method so that the correct gender is printed.
3. The startup code I gave you for the Test class has two statements making up the method testPerson. Rewrite the
method so that it requires one statement.