Discussion 2 handout

Group members (names & NetIDs)

Objectives

Problem 1: Object diagrams

Draw labeled boxes for variables “x”, “y”, “a”, and “b”. Then execute the following assignment statements by hand, adding and erasing values and arrows in your diagram accordingly.

    x = 3;
    y = 2 * x;
    x = 7;
    z = y;

    a = "world";
    b = a;
    a = "hello";
object diagram template

Problem 2: Array initialization

Initialize an integer array containing two “1”s in two different ways.

One way

Another way

Initialize an integer array containing one hundred “1”s.

Problem 3: Multidimensional arrays

Draw an object diagram to illustrate execution of the following statements:

int[][] a = new int[3][];
a[0] = new int[]{3, 1, 4};
a[1] = new int[]{1, 5};
a[2] = a[0];
a[2][1] = 2;

Recall the semantics of the assignment statement from last week’s discussion. Based on that, what should happen when the following statement is executed?

a[1][2] = 9;

Problem 4: Program arguments

Implement an “echo” program that prints each argument passed to it, separated by spaces.

Example:

$ java Echo My name   is  Hal.
My name is Hal.
public class Echo {
    public static void main(String[] args) {






    }
}

Submission

  1. Open the assignment page for “Discussion activity 2” in CMSX
  2. [Recorder] Find the “Group Management” section and invite each group member
  3. [Others] Refresh the page and accept your invitation
  4. [Recorder] Take a picture of your work and save as either a JPEG or a PDF file named “discussion_responses”. After all invitations have been accepted, upload your picture along with your code as your group’s submission.
    • Recommended scanning apps: Microsoft Office Lens, Adobe Scan, Genius Scan, Evernote Scannable

Ensure that your group is formed and your work submitted before the Friday evening deadline.

Tips and reminders