Week 14 · 14.1 · Mon, Nov 2 · Do Now
Work every question in your notebook. Do it on your Chromebook with your ID.
Trace row
Trace these lines. What do the boxes hold after line 4?
c ← 37 k ← 8 e ← c ÷ k ok ← c rem k = 5
- c = 37, k = 8, e = 4, ok = true
- c = 37, k = 8, e = 5, ok = true
- c = 37, k = 8, e = 4, ok = 5
- c = 37, k = 8, e = 4, ok = false
Predict
What is shown? The first line shown is first.
a ← 9 b ← a a ← a * 4 show b show a rem 5
- 9, then 1
- 36, then 1
- 9, then 7
- 36, then 7
Error analysis
A student traced these lines and wrote that each holds 0. The right answer is 7. What mistake did the student make?
total ← 45 bags ← 6 each ← total ÷ bags
- The student divided 6 by 45, upside down.
- The student used rem instead of ÷.
- The student rounded 7.5 up.
- The student skipped line 1.
Pick the rule
Which question is true exactly when n pieces of candy can be split into groups of 3 with none left over and n is less than 30?
- n rem 3 = 0 and n < 30
- n ÷ 3 = 0 and n < 30
- n rem 3 = 0 or n < 30
- n rem 3 ≠ 0 and n < 30
Output
Trace these lines. Write exactly what is shown, one line for each show.
candy ← 43 kids ← 6 each ← candy ÷ kids left ← candy rem kids show each show left = 1 and each > 7
Turn and Talk, Part 1: What went wrong?
Turn and Talk · Part 1 · talk with your partner first.
- “I think the mistake is in line ___ because ___.”
- “I agree / disagree, because ___.”
A student wrote this program, and it does not run. Talk with your partner: what went wrong?
public class Hello { public static void main(String[] args) { System.out.println("Hi") } }- Line 3 should not have (String[] args)
- Line 5 is missing its semicolon
- The braces on lines 4 and 6 do not match
- "Hi" needs single quotes
Turn and Talk, Part 2: Is it right now?
Turn and Talk · Part 2 · talk with your partner first.
- “I think it is right now, because ___.”
- “I think it is still wrong at line ___, because ___.”
The student added the semicolon and sent this. Is it right now?
public class Hello { public static void main(String[] args) { System.out.println("Hi"); }- Still wrong: the class's closing brace is gone
- Right: it prints Hi
- Still wrong: line 5 needs a second semicolon
- Still wrong: main must come before the class