teaching machines

CS 145 Lecture 5

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

Agenda

Code

GeometryFun.java

package lecture;

import java.util.Scanner;

public class GeometryFun {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter radius: ");
    double value = in.nextDouble();
    double area = getAreaOfCircle(value);
    System.out.println("Area: " + area);
    
//    getAreaOfCircle("t");
    
    System.out.println(getAreaOfAnnulus(6, 8));
  }
  
  public static double getAreaOfCircle(double radius) {
    double area = radius * radius * Math.PI;
//    radius = 6.0; // this has absolutely no effect on anything at all
    return area;
  }
  
  // meaningful name?
  // return type?
  // outside information?
  
  public static double getAreaOfAnnulus(double insideRadius, double outsideRadius) {
    double insideArea = getAreaOfCircle(insideRadius);
    double outsideArea = getAreaOfCircle(outsideRadius);
    double totalArea = outsideArea - insideArea;
    return totalArea;
  }
  
  public static double f(double t) {
    return 1 / (1 + Math.sqrt(t));
  }
//  
//  public static double getEdgeOfCube(double diagonalLength) {
//    // find diagonal of bottom face
//    // 
//  }
}

TODO

Haiku

dragon before princess
bread before peanut butter
thinking before code