teaching machines

CS 145 Lecture 2 – Expressions, Operators, and Variables

September 5, 2014 by . Filed under cs145, fall 2014, lectures.

Agenda

TODO

Reading Review

  1. What format does a class name follow?
  2. A method name?
  3. What’s the purpose of a comment?
  4. How do you print a double-quotation mark?
  5. 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:

  1. Walk a square.
  2. Walk a pentagon.
  3. Walk a hexagon.
  4. Walk an n-gon.

Program This 2

  1. 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