Discussion 2 handout
Requirements reminder
- Form a group of 3-5 classmates seated near enough to allow discussion.
- Record the group’s responses to each activity on a sheet of paper.
- Register your group in CMS, then upload a photo or scan of your work. The submitted paper must include the names and NetIDs of all group members and your responses to each problem discussed during section.
Problem 1: Array initialization
Initialize an integer array containing two “1”s in two different ways.
Initialize an integer array containing one hundred “1”s.
Problem 2: 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[0][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[2][2] = 9;
Problem 3: Program arguments
(Your TA may treat this as a demo instead of an exercise if time is short; in that case, a response is not required on your worksheet.)
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) {
}
}
Problem 4: Code style
Download IntHeap.java from the course website and skim it. Discuss: what about this code makes it harder to understand than necessary?
You do not need to understand what the class is for or how it works. But you should understand the effects of individual statements. If any syntax (aside from throws
, which we’ll get to in lecture 8) is unfamiliar, ask about it.
Install the class formatting preferences in IDEA. Have one group member reformat IntHeap.java while another retains the original. Compare the formatted copy to the original.
Are there aspects of the original format that you prefer?
Are there deficiences that reformatting did not fix?
Submission
- Open the assignment page for “Discussion activity 2” in CMSX
- [Recorder] Find the “Group Management” section and invite each group member
- [Others] Refresh the page and accept your invitation
- [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 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
- Discussion is not a race. Focus on the current activity being facilitated by your TA and enage your whole group to propose and explain ideas.
- Elect a recorder to maintain the “master” copy of your work (others are still encouraged to jot down ideas on scratch paper). Rotate this position each week.
- It is a violation of academic integrity to credit someone for work if they were not present when the work was done, and the whole group is accountable. Your CMS group must only include classmates who attended section with you on that day. Remember that our participation policies accommodate occasional absences without penalty.
- It is your individual responsibility to ensure that you are grouped on CMS and that your group’s work is submitted before the deadline. Log into CMS the day after section to ensure that everything is in order, and contact your groupmates if not. It would be prudent for multiple members to photograph the group’s work.
- Only one group member (typically the recorder) needs to upload a submission. But their submission must not be uploaded until after all group members have confirmed their membership in CMS (contact your TA if you have trouble grouping in CMS).