Discussion 1 handout
Learning to program requires more than just acquiring knowledge. You need to actively explore the implications of new concepts to build mental connections, and you need to practice writing programs just like athletes and musicians need to practice their skills. Programming assignments provide the latter, while discussion sections are meant to stimulate the former.
Discussion implies interaction—to thoroughly explore these concepts, you need to formulate your thoughts into words, and you need to accommodate ideas from others in your evolving mental model. Therefore, discussion sections are structured around cooperative exercises to be completed in groups and synthesized by the class as a whole. This is the first such exercise.
Requirements
- 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.
Tips and reminders
- 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).
Problem 1: Variable 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;
a = "world";
b = a;
a = "hello";
Problem 2: Semantics of the assignment statement
Write the procedure for how you would execute an assignment statement such as “y = 2 * x;
”, or more generally, “<var> = <expr>;”. Select steps from the following choices, re-ordering them as necessary.
- Store the value in the variable on the left-hand side.
- Create the variable on the left-hand side.
- Allocate memory for the type of the variable on the left-hand side.
- Evaluate the expression on the right-hand side.
- Check if the value can be stored in the variable on the left-hand side.
Problem 3: Dynamic vs. static typing
Brainstorm at least two reasons each for why software might benefit from being written in a dynamically-typed language and at least two reasons why it might benefit from being written in a statically-typed language.
(Tip: Are there implications for how easy code is to read or write? What happens when you accidentally write buggy code?)
Advantages of dynamic typing
Advantages of static typing
Problem 4: Create a Java project
If you have your own laptop with IntelliJ already installed, try to follow along as your TA demonstrates how to create a new project. If no one in your group has a laptop, that’s okay—watch the TA’s example carefully, then complete tasks 5 & 6 on your worksheet.
Task
- Create a new Java project named “Lab01”
- Make sure the JDK is set to version 17 (if downloading from within IntelliJ, choose Eclipse Temurin)
- Take note of the project’s location (the folder on your hard drive where its files are stored)
- Create a new Java class named “Lab01Main” in the “src” folder
- Add a “main method” to your class by typing the following inside of the class definition (between the curly braces):
public static void main(String[] args) {
// Compute total travel distance
int dist = 0;
}
- Perform a peer review! Check the following about your groupmate’s code (copy this checklist to your worksheet and check off each item as you complete it):
- The class is named Lab01Main
- The class is in the “src” folder
- The main method is inside the class definition
- There are no syntax errors (red squiggles)
- Copy the variable declaration and initialization
int dist = 0;
to your worksheet and close your laptops. Pass around your worksheet, with each group member adding a line to increment the variable dist
by the (approximate) number of miles they traveled to get to Ithaca during move-in. Check your syntax carefully (does each statement end with a semicolon?)
- Add a line to print “Our group traveled X miles to get to Ithaca.”, where X is the value of your
dist
variable.
- Open your laptop and type the lines you wrote verbatim into your main method. If your IDE flags syntax errors, fix them on your worksheet as well.
- Run your main method and copy its output to your worksheet.
public static void main(String[] args) {
// Compute total travel distance
int dist = 0;
}
Output
Submission
- Open the assignment page for “Discussion activity 1” 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.