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 2-4 classmates seated near enough to allow discussion.
- Remember to still record your answers separately and turn them in on CMSx, most text formats should be accepted by CMSx.
Objectives
- Setup and Install IntelliJ
- Identify declarations, expressions, and assignments in Java methods
- Debug test failures in the IntelliJ IDE
- Types in Java
- Get Started with Assignment 1 (due this Friday)
Problem 1: Introductions
Share your name & NetID, year & college, and a fun fact about yourself with your groupmates. Record the names and NetIDs of all group members.
Discuss the following two questions with your group, recording a representative answer:
Why do you want to learn object-oriented programming and data structures? (is it relevant to your intended major or career? did you enjoy your experience in your prior CS class? is there something particular you hope to accomplish with the knowledge?)
What was the most difficult concept in your previous programming class? (recursion? sorting? objects? arrays?) Does someone in the group have an example that helped the concept click for them?
Problem 2: Install and set up IntelliJ
Follow the instructions here and go ahead and setup your environment. Ask the instructor for help if you get stuck.
Problem 3: Open and debug a Java project
- Download the “dis01” project archive from the course website and extract its contents to a folder on your computer.
- Open the “dis01” directory as a project in IntelliJ. See our setup page for step-by-step instructions.
- Read the method specifications in “src/cs2110/Dis01.java”.
- Run the
Dis01Test
test suite and note which test cases are failing. - For each method, try to determine where the bug is. If you have trouble spotting it, try printing the results of intermediate calculations to see if they match your expectations.
- When you think you have identified the issue, fix the bug and re-run the test suite to confirm.
- Reformat “Dis01.java” by going to Code | Reformat Code. You are now done with this problem.
Problem 4: Practice with Types
Though we have discussed Types in java briefly. It is impossible to cover every java type in detail. This is opportunity for you to get more practice with Java’s type system.
Please see the following code snippet in the main main()
function of your Dis01.java.
/** For the following lines. And report the following information for each of these statements below:
* Does an error occur on this line? If yes, what kind and how to fix it
* What is are the state of the variable before the corrected/correct statement is executed?
* What is are the state of the variable after the corrected/correct statement is executed?
* Of the concepts we've learnt in the past 2 lectures, what applies to each of these code snippets?
* :Remember that the terms we've used so far is primitive types, Classes, overloading, casting.
**/
// S1:
int a = "Hello";
// S2:
String s1 = 1 + 2 + "abc";
String s2 = "abc" + 1 + 2;
// S3:
String b1 = "abc".charAt(1);
String b2 = "" + "abc".charAt(1);
// S4:
int a1 = 10.0;
int a2 = (int) 10.0;
int a3 = 1 + 10.0;
double a4 = 1 + 10.0;
S1:
Problem 5: Spend Time on Assignment 1
If you’ve completed all the other problems. Please spend the remaining time on solving A1. This part of the discussion must be done individually. Do not discuss a1 with any of your classmates. This time is meant for you work on a1 under the guidance of the instructor. This is mainly to offset the tight timelines for assignment due dates and the lack of teaching staff to assist you at your convenience.
Submission
- Open the assignment page for “dis1” in CMSX
- Even if you work in a group, please turn in your submissions individually.