Week 14 · 14.2 · Wed, Nov 4 · Do Now
Work every question in your notebook. Do it on your Chromebook with your ID.
Match the braces
Which line holds the brace that closes main?
public class Library { public static void main(String[] args) { System.out.println("Find a book"); System.out.println("Check it out"); System.out.println("Read"); } }- line 2
- line 4
- line 8
- line 9
Count statements
How many statements does main hold?
public class Trip { public static void main(String[] args) { System.out.println("Pack"); System.out.println("Load the car"); System.out.println("Drive"); System.out.println("Stop for gas"); System.out.println("Arrive"); } }- 3
- 4
- 5
- 7
Error analysis
A student says this program prints Five more minutes first. The right answer is Alarm. What mistake did the student make?
public class Morning { static void snooze() { System.out.println("Five more minutes"); } public static void main(String[] args) { System.out.println("Alarm"); System.out.println("Get up"); } }- The student started at the top of the file instead of at main.
- The student matched the braces on lines 4 and 6 wrong.
- The student forgot that each statement ends with a semicolon.
- The student read main's statements from bottom to top.
Statement
Which of these is one complete Java statement?
- System.out.println("Stop");
- System.out.println("Stop")
- public class Stop
- }
Output
Write exactly what this program prints, one line for each line of output.
public class Game { static void overtime() { System.out.println("Overtime"); } public static void main(String[] args) { System.out.println("Kickoff"); System.out.println("Halftime"); System.out.println("Final whistle"); } }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 down this program's output. Talk with your partner: what went wrong?
public class Morning { public static void main(String[] args) { System.out.println("Wake up"); System.out.println("Eat"); System.out.println("Go"); } }The student's output Line Shown 1 Go 2 Eat 3 Wake up - The student read the lines bottom to top
- The student skipped a line
- The student printed the quotation marks
- Nothing: the output is right
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 tried again. Is it right now?
public class Morning { public static void main(String[] args) { System.out.println("Wake up"); System.out.println("Eat"); System.out.println("Go"); } }The student's new output Line Shown 1 Wake up 2 Eat 3 Go - Right: Wake up, Eat, Go, top to bottom
- Still wrong: main runs last
- Still wrong: it prints all three words on one line
- Still wrong: line 7 runs first