Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Umple lab instructions
Purpose: To enable you to understand how UML can be translated into Java
code, and how Umple allows you to write code that includes UML
constructs.
It is necessary to follow the instructions exactly so you do not experience
syntactic and semantic errors.
Why learn Umple? The reason is simply that we believe no other tool exists
allows you so easily to learn about the relationship between a UML model
and generated Java code. Umple allows you to edit a UML model both
textually and graphically, and also to incorporate UML directly into Java
code.
It is suggested that you work in groups of two on this lab. You will need to
keep this file open since there are things you will need to copy and paste
from here to a web browser.
1. Get set up by going to the following website
http://cruise.site.uottawa.ca/umpleonline/
You will see a window with three areas.
On the right is an area where you can draw UML diagrams.
In the middle are some icons or labels you can click on to issue commands.
On the left is an area that will contain code in the Umple language. The Umple code
looks a lot like Java. It can contain declarations of UML entities like classes, attributes
and associations. It can also contain ordinary Java methods.
Later on we will show you a fourth pane that appears below with generated Java code.
1 of 8
2. Do the following to draw a UML class diagram and make Umple code
appear
a) Click on the ‘class’ icon, then click on the right pane in the webpage.
You should see a UML class symbol with the name NewClass.
b) Double-click on the class name and edit it so it changes from NewClass to
Student
Notice that on the left hand side of the screen you see ‘class Student{}’. Umple converts
whatever you type as a diagram into a textual form.
c) Click in the attributes area of the Student class where the text says ‘--Add
More --‘, then replace this by ‘studentID: Integer’.
You just added a UML attribute.
Notice on the right side it now says ‘Integer studentId;’.
It has converted UML syntax into Umple textual syntax, which is also Java syntax.
d) Add another attribute called ‘name’. Don’t explicitly give it a type.
Notice that the type ‘String’ is automatically added if you don’t specify a type in the
UML diagram.
e) Click on ‘Options’ in the middle panel, and select ‘layout editor’.
You will see the ‘position’ information appear at the bottom of the left panel. This is
Umple’s way of storing the layout of the diagram separately from the model.
f) Drag the Student class around in the right hand panel.
You will see the position information being adjusted.
g) On the left hand text panel edit the word ‘name’ so it says ‘fullName’.
Notice that the UML diagram on the right hand side changes.
2 of 8
3. Do the following to generate Java code
a) In the middle panel, make sure the ‘Tools’ panel is displayed, and below
the ‘GENERATE’ label it says ‘Java Code’. Then click on the button that
says ‘Generate Code’.
You will see a label pop up for a few seconds saying that code generation is complete.
b) Now click on right pane and scroll down.
You will see the java code for the student class that you had created earlier.
Notice that the attributes have been converted into private fields, and getter and setter
methods have been created.
3 of 8
4. Do the following to create and work with an association
a) Click on LOAD & SAVE in the middle panel, and then on ‘Start Over’.
You will notice that UmpleOnline is reset with blank panes.
b) Select the code in yellow below and paste it into the left-hand pane,
class Student
{
Integer studentID;
String fullName;
}
class CourseSection
{
String idLetter;
}
//$?[End_of_model]$?
class Student
{
position 92 32 151 85;
}
class CourseSection
{
position 100 243 127 65;
}
You will see the corresponding class diagram appear in the right-hand pane.
c) Click on the ‘Association’ icon in the middle pane.
d) Then click in the right pane on the Student class followed by the
CourseSection class.
You will see a many-to-many association appear both graphically on the right pane, and
textually on the left pane.
(By the way, after selecting ‘Association’ you could also have just dragged the cursor
from the Student to the CourseSection class, or you could have textually added the string
‘* -- * Student;’ to the CourseSection class in the left pane).
4 of 8
e) Generate the Java code.
Notice that the Java code has about 292 lines of code, much more than the Umple code
f) Delete the association you just created by editing the Umple code in the
left-hand text pane.
(By the way, you could have also deleted it from the right-hand graphic pane or by
clicking ‘undo’ in the middle pane.)
5 of 8
5. Do the following to create and work with an association class
a) Add a third class called Registration with an attribute grade. (You can do
this by editing the diagram in the left pane, or the text in the right pane)
b) Add two associations. One between Student and Registration, and one
between Registration and Course Section.
If you have trouble, you can press the ‘start over’ button and then paste the code in green
below into the left pane.
class Student
{
Integer studentID;
String fullName;
}
class CourseSection
{
String idLetter;
* -- * Registration;
}
class Registration
{
* -- * Student;
}
//$?[End_of_model]$?
class Student
{
position 92 32 151 85;
}
class CourseSection
{
position 100 243 127 65;
position.association CourseSection__Registration 127,25 40,46;
}
class Registration
{
position 299 146 109 46;
position.association Registration__Student 47,0 151,39;
}
6 of 8
c) The associations you just added are many-to-many. Change them to that
Registration becomes a proper association class with only 1 Student and 1
Course Section. You will have to edit the text on the left to accomplish this,
since multiplicities are not yet editable in the diagram.
d) When you reach this point, show the TA, so that he or she can verify that
you have done this correctly.
e) Generate the code and study the resulting approximately 500 lines of Java
code.
7 of 8
6. Creating a running Java program with code generated from Umple.
a) Start Eclipse and create a new Java project.
b) Create three java classes files in Eclipse, and paste the code generated by
Umple into those files.
(by the way, you could have written the Umple classes directly in Eclipse and compiled
them there, since there is an Eclipse plugin for Umple)
c) Create a fourth class called RegistrationTestDriver. This class will just
have a main program. The main program should
- Create a Student by calling the constructor with a student ID and a name.
- Create a CourseSection, passing it an ID letter.
- Create a registration, passing it the Student and Course Section.
When doing the above you must not modify the Student, CourseSection or Registration
classes at all.
d) Change the Umple model so that registration has a grade that does not
have to be specified in the constructor of Registration.
You can do this by adding an attribute with an initiual value: grade = “ ”; (in text pane)
e) Regenerate the Java code and figure out what line or lines changed.
f) Copy the changed code into your Eclipse code and modify your
RegistrationTestDriver class so it works with the new code.
g) Add an extra class to the Umple text pane on the left, called ‘Course’ with
a single attribute ‘name’. Don’t worry about the position information in the
diagram.
h) Add an association by pasting in the Umple code below
association
{
1 Course -- * CourseSection;
}
i) Generate the code and figure out what has changed.
j) Before you leave the lab, show the TA your revised Umple model and also
the results of step f above where you modified the Java driver.
8 of 8