teaching machines

CS 145 Lecture 8

October 3, 2011 by . Filed under cs145, fall 2011, lectures.

Agenda

Code

Summer.java

package lecture;

public class Summer {
  public static void main(String[] args) {
    System.out.println(sum(100));
  }

  public static int sum(int n) {
    int runningTotal = n;
    
    while (n > 0) {
      n = n - 1;
      runningTotal = runningTotal + n;
    }
    
    return runningTotal;
//    return 1 + 2 + 3 + 4 + ... + n; 
  }
}

Animation.java

package hw1;

import cs145.s2011C.hw1.Animator;
import cs145.s2011C.hw1.Figure;

public class Animation {
  public static void main(String[] args) {
    Animator animator = new Animator();
    Figure figure = new Figure();
    
    figure.turn(90);
//    animator.register(figure, 0);
//    
//    figure.turn(1800);
//    animator.register(figure, 10);
    
    takeStep(figure, animator, 0);
    takeStep(figure, animator, 5);
    takeStep(figure, animator, 10);
    takeStep(figure, animator, 15);
    takeStep(figure, animator, 20);
    takeStep(figure, animator, 25);
    takeStep(figure, animator, 30);

    
    animator.show();
  }
  
  public static void takeStep(Figure philJedSteve, Animator animator, double startAt) {
    philJedSteve.bendLeftLeg(45);
    philJedSteve.bendRightLeg(-45);
    animator.register(philJedSteve, startAt + 0);
    
    philJedSteve.bendLeftLeg(-90);
    philJedSteve.bendRightLeg(90);
    animator.register(philJedSteve, startAt + 2.5);
    
    philJedSteve.bendLeftLeg(45);
    philJedSteve.bendRightLeg(-45);
    animator.register(philJedSteve, startAt + 5);
  }
}

TODO

Haiku

Boole, that cleaving knife
good/bad, married/single, bah!
“It’s complicated”