teaching machines

CS 145 Lecture 5 – More on the Math Class


  • what ?s
  • quiz tomorrow
  • blackboxes
  • more math problems
  • switching between types


  • Tomorrow in lab is our first quiz. Prepare a question (or two or three, in case yours gets nabbed by someone else) to share with your lab group before the quiz. Topics we’ve hit upon so far include: the arithmetic operators, variables, types and switching between them, and methods in the Math class. Avoid obscure trivia and showboating. At the same time, avoid questions that don’t require some amount of thought (e.g., ints hold numbers, true or false?)


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.



package lecture0914;

public class Blackboxing {
  public static void main(String[] args) {

    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;


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


Leave a Reply

Your email address will not be published. Required fields are marked *