0% found this document useful (0 votes)
72 views

Software Engineering: Analysis and Design ITECH 7201 Laboratory 1

This document provides instructions for a software engineering lab assignment. Students are asked to: 1) Create abstractions for concepts like "Car", "Book", and "Person" by identifying 3 defining attributes for each. 2) Use Enterprise Architect to build a basic UML class diagram for one of the concepts, including attributes, get/set methods, and constructors. 3) Implement the class diagram in Java code. 4) Download and modify a test class to test the Java implementation by filling an array or ArrayList with objects and printing their details. Optional challenges are also provided.

Uploaded by

Inderbir Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Software Engineering: Analysis and Design ITECH 7201 Laboratory 1

This document provides instructions for a software engineering lab assignment. Students are asked to: 1) Create abstractions for concepts like "Car", "Book", and "Person" by identifying 3 defining attributes for each. 2) Use Enterprise Architect to build a basic UML class diagram for one of the concepts, including attributes, get/set methods, and constructors. 3) Implement the class diagram in Java code. 4) Download and modify a test class to test the Java implementation by filling an array or ArrayList with objects and printing their details. Optional challenges are also provided.

Uploaded by

Inderbir Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Software Engineering: Analysis and Design

ITECH 7201

Laboratory 1

Task 1. – Making some abstractions

Watch the video at the following link (if you haven’t done so already)

ObjectOrientedProgrammingDesign. (Apr 2014). Foundations of programming object-oriented design.


What is abstraction.

Create abstractions for the following three everyday concepts:


 Car
 Book
 Person

The idea is to find three things that help define that object (the way “size” and “colour” defined Apple in the
video).

Person Car Book

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.

Task 2 – Enterprise Architect Class diagrams

CRICOS Provider No. 00103D Insert file name here Page 1 of 5


You are going to use EA to create a few different kinds of UML models this semester. Today you are going to
create a very simple class diagram consisting of one class. This can be a class of your choice from one of
the three abstractions you created in Task one. The class diagram should contain:
 Your three attributes
 Get and set methods for these three attributes
 A toString method
 2 constructors
o A default constructor (no parameters)
o A constructor with three parameters which will be used to initialize your attributes

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

CRICOS Provider No. 00103D Insert file name here Page 2 of 5


 Check that they are all correct in the text box at the bottom
 Click Close

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

The class might look as follows:

CRICOS Provider No. 00103D Insert file name here Page 3 of 5


When you’ve finished drag a second class onto the pane and create a class diagram for one of your other
abstractions.

Task 3. Create a Java class

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).

Task 4 – Test the Java Class

Download the Test class from Moodle and add it to your lab01 package.

 Adjust fillArrayWithPersonObjects to have all 5 array elements filled


 Adjust printPersonObjects to print out 5 Person elements instead of two.

Optional/Challenge tasks

CRICOS Provider No. 00103D Insert file name here Page 4 of 5


1. Rewrite the fillArrayWithPersonObjects, and printPersonObjects methods to use an ArrayList instead of an array
(only attempt if you have used ArrayLists before)
a. Note you will need to use templates (which you haven’t come across before. However, it’s simple
enough)
i. ArrayList<Person> personList = new ArrayList<Person>( );
ii. So everywhere you would have used ArrayList simply type <Person> afterwards.

What is the advantage of using an ArrayList rather than using an array?

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.

CRICOS Provider No. 00103D Insert file name here Page 5 of 5

You might also like