teaching machines

CS 145 Lecture 2

September 12, 2011 by . Filed under cs145, fall 2011, lectures.

Topics Covered

What does this do?

  1. int a = 7;
    int b = 3;
    b = a + b;
  2. int i;
    System.out.println(i);
  3. int i = 100;
    System.out.println(i / 0);

Code

WhatDoesThisDo1.java

package lecture;

public class WhatDoesThisDo1 {
  public static void main(String[] args) {
    // Variables must be initialized!
//    int i;
//    System.out.println(i);
    
    // Crashes at runtime!
    int i = 100;
    System.out.println(i / 0);
  }
}

Paperclipping.java

package lecture;

public class Paperclipping {
  public static void main(String[] args) {
    int nClips = 22025;
    int nHours = 24;
    double hoursPerMinute = 1.0 / 60.0;
    double minutesPerSecond = 1.0 / 60.0;

    double jeannesRate = nClips / nHours * hoursPerMinute * minutesPerSecond * 6;
    System.out.println(jeannesRate);
    
    double yosRate = 4.0;
    
    System.out.println(yosRate > jeannesRate);
  }
}

CowpathSavings.java

package lecture;

public class CowpathSavings {
  public static void main(String[] args) {
    double cosOf31 = Math.cos(31);
    System.out.println(cosOf31);
    
    double a = 10.0;
    double b = 20.0;
    
    double cowpath = Math.sqrt(a * a + b * b);
    System.out.println(cowpath);
    double savings = a + b - cowpath;
    System.out.println(savings);
    
    // (10 * 10) + (20 * 20) = c * c
    // (
    
  }
}

TODO

Haiku

folks steal my poems
thought in penless laundry rooms
written in quarters