M/F 2:30-3:20   
in G01 Gates Hall

CS 1130: Transition to OO Programming

Spring 2016

Diagraming Objects and Frames

Due in class or to CMS on Friday, February 13th.

This is a simple written assignment where you are going to diagram a few objects. It should not take more a few minutes do to this assignment. So even if you are busy revising assignment 1, you should be able to do this assignment as well.

"Diagraming" is what we do in the lecture notes where we draw the folders to represent the objects and associated variables. It also includes the methods frames that we talked about in class. These are a way of giving us a visual repreentation of what is going on in the computer when it runs Java. The purpose of this assignment is to see if you can keep track of what goes where in an object.

Before You Get Started

Collaboration Policy

Unlike the previous assignment, we would like you to do this assignment on your own. The purpose of this assignment is to assess that you understand the material well enough to carry it out on the exam at the end of the course.

Academic Integrity

For this assignment, you must work on your own. Do not share your assignment with others; do not obtain or look at a copy of an earlier solution or a version from another sturent. Because purpose of this assignment is to assess your understanding before the exam, it only hurts you if you cheat on this assignment.

Grading Policy

As with the previous assignment, you are to resubmit this assignment until you pass. However, for this assignment, passing is considered 85%. You do not have to get a perfect to pass.

We will not outline our grading scheme in this assignment. If you do not pass you will be told what to revise. Hopefully, everything should be correct within one revision.

Getting Help

If you do not know where to start or if you are completely lost, please see someone immediately. This can be the course instructor, a TA, or a consultant. Do not wait until the last minute. A little in-person help can do wonders. See the staff page for more information.

Diagramming Conventions

Most of our diagramming conventions follow the lecture notes. However, in some places the lecture notes cut corners in order to be able to fit all the information on the slide. We do not want you to do that here. Therefore, we make several explicit conventions.

Diagramming Variables

A diagram for a variable should include the variable name, a box for the value, and a type. For example, here is a diagram for the variable x:

We sometimes dropped the type in lecture, but you should not do that for this assignment.

Diagramming Objects

When you diagram a folder (object), you should obey the following conventions:

  • The folder name should be unique, start with an @, and go to the right.
  • The class name should go in a box to the right
  • The fields should be listed just below the tab name and diagrammed just like variables.
  • The methods should go below the fields, separated by a dotted line.
  • You only need to give the method name and parameters for each method.
  • The constructor is a method; you should include it.

For example, a folder for a class Point1d might look like this:

Diagramming Classes

When you diagram a file drawer (class), you should obey the following conventions:

  • Draw the file drawer as a box.
  • Folders go at the top and are arranged horizontally.
  • Variables that belong in the file drawar (and not in the folders) go below the folders.
  • Methods that go in the file drawer go at the bottom and are separated by a vertical line
    (just as they are in the folders).

The following shows the basic structure of a class with all of the details removed

Diagramming a Frame for a Method Call

Frames should obey the following conventions:

  • The top left corner is a box with method name and instruction counter.
  • The top right corner is a box containing the scope of the method call.
  • The local variables and parameters diagrammed as variables in the frame body.

See the lecture notes for more details on how to create a frame for a method call. In this exercise, we will not worry about putting local variables in a frame. Furthermore, the instruction counter will start at 1.

Assignment Instructions

The Class Example

This entire assignment will revolve around the following class:

public class Example {
   public static final int ZERO = 0;
   private int h;

   public Example(int ph) {
      h = ph;

   public int getH() {
      return h;

   public void setH(int h) {
      this.h = h;

Step 1: Diagramming Folders

Given the class above, suppose we were to execute the following commands:

  Example e = new Example(3);
  Example f = new Example(5);
  Example g = e;

Diagram the variables e, f, and g and the folders associated with them. The folders should only include fields and methods that are specifically associated with folders (and not those associated with file drawers).

Step 2: Diagramming a File Drawer

Extend the diagram in the previous step so that the folders that you created are now in a file drawer representing the class Example. If there are any variables or methods that should go in the file drawer (e.g. you did not include them in the previous step), add them now.

Step 3: Diagramming a Frame for a Method Call

Extend your diagram once again to include frames for the following method call:


Do not erase the frame. We just want to see what the frame looks like at the start of the method class (e.g. before line 1 is executed).

Step 4: Diagramming a Frame for a Constructor Call

In step 1, you were given the command

  Example e = new Example(3);
The constructor for Example is a (special type of) method, and so the new command creates a method frame for the constructor when you use is. Diagram this method frame.

Turning it In