teaching machines

CS 145 Lecture 5 – More on the Math Class

September 14, 2015 by . Filed under cs145, fall 2015, lectures.

Agenda

TODO

Note

Today we’ll hit upon two topics that we missed somewhere along the line in our earlier discussion: concatenating with Strings and naming conventions for names or identifiers that we use in our code.

We’ll also reason about a few blackboxes, which in some sense are like the methods we rely. We feed values in and get back out some new value that gets us closer to the answer we want. Sometimes, however, we wonder how on earth these methods do the work they do…

We’ll close by using math and programming ideas to make something useful: a Hyrulean rupee.

Code

Blackboxing.java

package lecture0914;

public class Blackboxing {
  public static void main(String[] args) {
    System.out.println(Math.abs(-5));

    double x1 = 2;
    double y1 = 4;
    double x2 = 6;
    double y2 = 8;

    double slope = (y2 - y1) / (x2 - x1);
    // double intercept

    double minOfFirstTwo = Math.min(x1, y1);
    double min = Math.min(x2, minOfFirstTwo);

    double min2 = Math.min(x2, Math.min(x1, y1));

    int a = 1;
    int b = 2;
    int c = 4;
    int sum = a + b + c;
    System.out.println((double) sum / 3);

    double m = 17.4;
    int n = (int) m;

    int o = 32;
    double p = o;
  }
}

Haiku

Kids grow their own bones
They ought to grow their own math
We must solve for I