Computer Science 260
Homework 1: UML Diagrams with DIA
Due: Wed. Feb. 14, at the beginning of class.
In this homework, you will become familiar with the Dia diagram editor and use Dia to draw a UML class diagram. Dia is available as a free download for Linux, MacOS and Windows from For this homework, however, you must create your submission on the departmental Linux server sand that we used in the Eclipse lab.
1)Login to sand. Open Dia by choosingApplications > Graphics > Diagram Editor. The Dia window is divided into the canvas (on the right side of the window), the tools pane (on the left), and the menu bar (in its usual location across the top of the window.) The canvas is marked off in a grid.
A printable page is shown by a solid blue rectangle on the grid. By default, Dia will show several pages in the canvas at once. Resize the Dia application window so that it fills the screen. Note that you can drag the image in the canvas using the scroll tool from the tools pain:. Change the magnification so that you see a single16.5-centimeter by 24-centimeter page in the canvas. You can change the magnification from the menu bar.
2)The "Library Selection List" is a drop down menu in the middle of the tools pane. Find the Library Selection List, click on it, and choose UML. The UML graphics rectangles and connectives appear at the bottom of the tools pane. You can find out what part of UML each shape represents by hovering over the shape with the mouse.
3)Create a box to represent a class called Person(): Click the "Class" shape on the tools pane, and then place the class rectangle by clicking in the canvas. You can move the class rectangle by selecting the pointer tool from the tools menu and dragging the rectangle. To delete a class box, select it with the pointer tool and hit <delete>.
4)Add methods and instance variables to the class by performing the following steps. (Remember that in UML, methods are called "operations" and instance variables are called "attributes".)
a)Right-click on the class rectangle and choose "properties". Click on the "Class" tab at the top of the properties window and enter "Person" as the class name.
b)Click on the "Operations" tab at the top of the properties window. Then click the "new" button in the upper-right part of the window. A window to add information about a method will appear.
c)We want to indicate that the Person class has a method with the signature String getName(). Enter "getName" in the "Name" textbox, and "String" for the type. Leave the other text boxes blank. Click "Apply". You should see the method description appear in the class rectangle. (You may have to move the "properties" window out of the way.) Notice that Dia uses UML notation for operations and attributes.
d)Add a method with the signaturevoid setName (String aName). Click the "new" button again and enter the Name and Type of the method as before. Then, find the section of the window labeled "Parameters:" and click the "new" button in thatsection. Enter "aName" for the Name of the parameter and "String" for the type in the "Parameter data" section. Leave the "Default value", "Direction" and "Comment" areas blank. Click "apply" to add the method description to the class rectangle.
e)Next we will add information about the instance variables in the class. Click on the "attributes" tab at the top of the Properties window. Add instance variables for "name" (a String) and "age" (an int) to the rectangle.
f)Click "OK" to dismiss the window.
5)Add the classes with the listed instance variables and methods to the diagram. At this point, do not worry if the class rectangles overlap. We will have a chance to clean the diagram up before we finish.
Class / Methods / Instance variablesEmployee / void setSalary (double salary)
double getSalary () / double salary
int status
Student / double getGPA()
String getMajor()
Course [] getCourseList() / Course [] courseList
Resident / String getDorm()
Course / void addStudent(Person student)
void removeStudent (Person student, int reason) / Person [] studentList
String building
int roomNumber
int MAX_ENROLLMENT
Main / Course aCourse
Person anEmployee
Person aStudent
6)We want the Resident rectangle to represent an interface rather than a class. Open the properties window for the Resident rectangle by right clicking on the Resident box, and selecting the "Class" tab. Enter "interface" in the "Stereotype:" textbox. Click OK.
7)Now we want to add arrows to illustrate the relationships between the classes and interfaces. Employee and Student are both subclasses of Person. Click on the inheritance arrow in the tools menu. Place the cursor inside the Person rectangle (the superclass) and then drag the mouse until the cursor is inside the Employee rectangle (the subclass). When you release the mouse button, an inheritance arrow will appear, and its endpoints should "snap to" the sides of the two rectangles. Use the arrow tool to drag the Employee class around. Notice how the arrow stays attached to the class rectangle.
Add another arrow to show thatPersonis the superclass ofStudent. If you make a mistake placing an arrow, select the pointer tool in the tools menu, then select the arrow, and then press the Delete key.
8)Add arrows to show the following additional relationships:
- Studentimplements the Resident interface
- MainusesCourse andPerson. (Recall that "uses" means a dependency relationship.)
- CourseaggregatesPerson with a multiplicity of 1:MAX_ENROLLMENT. To add the multiplicity to the aggregation, draw the aggregation arrow. Then, right-click on the arrow and choose properties. Side A is the aggregating class, and side B is the class being aggregated (MAX_ENROLLMENT). Add the appropriate multiplicity to the B-side of the arrow. Leave the A side of the arrow blank.
9)Your diagram might be a bit of a mess at this point. To ensure that your diagram is easy for the implementer to understand, you will want to make sure that the class boxes and relationships are easy to see.
Drag the rectangles and arrows around until they are organized in an attractive and eye-pleasing manner. Your diagram must adhere to the following specifications:
- Ensure that arrows don't pass through class rectangles
- Related classes should be close to one anther if possible.
- Two arrows of the same type can merge, but don't allow arrows of different types to merge. If you can't get arrows to obey these specifications by moving class rectangles, you can change the routes of the relationship arrows. Do this by selecting the arrow with the pointer tool, and then dragging the routing lines and arrowheads.
Remember that good program designers always have attractive and pretty UML diagrams. Do not worry at this point if a class rectangles or arrowsextend beyond the page margins.
10)Add descriptive text to one of the upper corners of your diagram. You can add text using the text tool available from the tools pane. The text should contain your name, "CS 260", and the assignment name "Homework 1".
11)To print your diagram, go to File > Page Setup... Click the "Fit to" checkbox, and choose 1 by 1. Click OK. Then choose FilePrint. If your printed document looks squished, change the orientation from portrait to landscape from the Page Setup... menu, and print again.
What to turn in: Submit the printed copy of your class diagram at the beginning of class on the due date.