Week 2 · Wednesday, Jan 13 · 2.3
Shortcuts and comments
x += 5 is a short way to write x = x + 5, and comments are notes for people that Java skips when it runs the code.
Minutes for each part of a 90-minute class.
Today we will
- score = score + 5 the long way, then score += 5 the short way
- The five shortcuts: += -= *= /= %=, each one uses the variable's old value
- x++ adds 1 and x-- takes away 1, each on its own line
- Three kinds of comments: //, /* */ and /** */
- Preconditions: what must be true before the code runs
- A comment should match what the code really does
Terms
compound assignment operatorincrementdecrementcommentJavadoc commentpreconditionpostcondition
AP topics 1.6, 1.8 · Learning objectives 1.6.A, 1.8.A · Skills 2.A, 3.A, 4.A, 4.B
10–35 min
Demonstration
Chromebooks open. Follow along on the Follow along jobs in We Do / You Do while Mr. Muggivan works the examples.
10–75 min
We Do / You Do
Follow along, then Part A (with help), Part B (on your own) and stretch. One code for the whole block.
Open We Do / You Do75–90 min
Exit Ticket
A few exam-style items to show what you learned today. One code.
Opens only in the last 15 minutes of class on this day.
Missed class? The Do Now and We Do / You Do stay open. Do them any time and submit your codes.