CS 145 Lecture 2 – Expressions, Operators, and Variables
Agenda
- what ?s
- 3-minute reading review
- program this 1
- statements vs. expressions
- arithmetic operators
- program this 2
TODO
- Set up your homework repository by following http://youtu.be/t5PZvkQeuF0. No 1/4 sheet.
- Go see Her in Davies this weekend. I have not seen this film, and I understand it has content that you may not be comfortable watching. Share your thoughtful but brief response about humanity, technology, love, and other themes of the film on an extra credit 1/4 sheet.
- Lab will be posted sometime this weekend. You may start early.
Reading Review
- What format does a class name follow?
- A method name?
- What’s the purpose of a comment?
- How do you print a double-quotation mark?
- Give examples in English (not Java) of a syntax error, a logic error, and a runtime error.
Program This 1
You are to program your partner. Your partner responds to only 2 voice commands: turn and step. Complete the following:
- Walk a square.
- Walk a pentagon.
- Walk a hexagon.
- Walk an n-gon.
Program This 2
- How good is your vehicle’s mileage? What do you need to know to quantify it?
Code
Expressions.java
package lecture0905;
public class Expressions {
public static void main(String[] args) {
System.out.println(5);
System.out.println(5 + 1);
System.out.println(360.0 / 7);
System.out.println(43.71 * 1.2 + 3.50);
System.out.println((153755 - 153434) / 9.153);
System.out.println(77 % 12);
System.out.println(1350 / 24);
System.out.println(1350 % 24);
}
}
Haiku
on my son’s grasp of symmetry: “No middle number!” He points at four urinals “Yes. That’s odd,” I say