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

Tips and reminders

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";
variable diagram template

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.

  1. (?)
  2. (?)
  3. (?)

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

  1. Create a new Java project named “Lab01”
    1. Make sure the JDK is set to version 17 (if downloading from within IntelliJ, choose Eclipse Temurin)
    2. Take note of the project’s location (the folder on your hard drive where its files are stored)
  2. Create a new Java class named “Lab01Main” in the “src” folder
  3. 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;
    }
  4. 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):
    1. The class is named Lab01Main
    2. The class is in the “src” folder
    3. The main method is inside the class definition
    4. There are no syntax errors (red squiggles)
  5. 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?)
  6. Add a line to print “Our group traveled X miles to get to Ithaca.”, where X is the value of your dist variable.
  7. 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.
  8. 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

  1. Open the assignment page for “Discussion activity 1” 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 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.