Howdy. 

Name, date on the paper received. 

It will be used for attendance. 

Results of the survey from yesterday: 

  (a) assignments generally due at 5pm

  (b) grace period generally until 2am 

No penalty for late submissions.

Appeals to your grader are encouraged. 

Everybody is allowed to test out (before or after) regardless.

That means: late submission or no submission at all. 

When you test out: 

(a) better grade is kept, lower grade is ignored

(b) it's your responsibility to make sure there's time and space for you

LH204 is small. 

Now about the daily attendance. 

On your paper mention your favorite TV show.

Also mention your favorite comedian. 

How about also your favorite song.

Now for attendance please bring daily a piece of paper from home. 

It should a summary on it that's at most half the page. 

The title: Previously on C212. 

So you need to capture the essential developments to date in the class. 

-- 

Java programs are made out of classes. 

Classes contain members (procedures and variables). 

Procedures are often called methods. 

Members can be static or non-static. 

Non-static members form blueprints. 

Classes model things, entities with these blueprints. 

At the time of their instantiation (when objects get created) constructors are run. 

Constructors are not members, they are initialization procedures for the blueprints. 

In Java we have: 

(a) primitive types

(b) non-primitive types (classes, reference types, user-defined types). 

Kinds of variables in Java: 

(a) static (they belong to a class, exist as soon as the class is compiled)
(b) non-static (belong to the objects, once the object is created)
(c) local
(b) params

Let's model a Point: 

public class Point {
  int x, y; 
  public Point(int x, int y) {
    this.x = x; 
    this.y = y;
  }
  public Point() {
    this(0, 0); 
  } 
  public double distanceTo(Point other) {
    return Math.sqrt( Math.pow( this.x - other.x, 2 ) + 
                      Math.pow( this.y - other.y, 2 ) ); 
  } 
  public static Point origin = new Point(); 
  public static void main(String[] args) {
    Point a = new Point(0, 3), 
          b = new Point(4, 0); 
    System.out.println( a.distanceTo(b) ); // prints 5 
    System.out.println( Point.origin.distanceTo(new Point(1, 1)) ); // prints 1.4142...
  }
}

Let's model a Line: 

public class Line {

  Point a, b; // the endpoints
  // these are the instance variables in this class

  public Line(Point p1, Point p2) { // constructor 
    this.a = p1; 
    b = p2; 
  }

  public double length() { // instance method
    return a.distanceTo(b); 
  }
  
}

How do you model a Triangle? 

https://en.wikipedia.org/wiki/Hero_of_Alexandria

https://en.wikipedia.org/?title=Heron%27s_formula

public class Triangle {
  Line a, b, c;
  public Triangle(Point a, Point b, Point c) {
    this.a = new Line(a, b);  
    this.b = new Line(b, c);  
    this.c = new Line(c, a);  
  }
  public double area() {
    double a = this.a.length(); 
    double b = this.b.length(); 
    double c = this.c.length(); 
    double s = (a + b + c) / 2; 
    return Math.sqrt( s * (s - a) * (s - b) * (s - c) ); 
  }
  public static void main(String[] args) {
    Triangle a = new Triangle( Point.origin, 
                               new Point(3, 0), 
                               new Point(0, 4) );
    System.out.println( a.area() ); // prints 6.0
    
  }
}

How do you generate random numbers in Java? 

public class LectureThree {
  public static void main(String[] args) {
    // Math.sqrt(...) generates the square root of its argument 
    // Math.pow(..., ...) 
    // Math.random() uniformly distributed in [0, 1)
    for (int i = 1; i <= 20; i = i + 1) {
      double n = Math.random();   
      System.out.print( (int) (n * 6 + 1) + " ");
    }
  }
}

The for loop will ensure that the code is repeated 20 times. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run LectureThree
4 4 6 4 6 6 6 4 6 6 6 3 3 3 2 1 6 1 1 1 > 

If I run it again:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run LectureThree
4 4 5 4 3 4 2 3 3 5 4 2 6 6 6 4 2 3 4 3 > 

See you in lab!

--