Answer key tonight and please check and let me know. 

Next exam: write programs. 

I will post a study guide for the next exam by Wednesday. 

Design a class Point. 

Design a class called Line. 

Design a class Triangle. 

Design a class Circle. 

In one program create a Point, a Line, a Triangle, a Circle ...

public class Point {
  private int x, y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
  public double distanceTo(Point other) {
    int dx = this.x - other.x;  
    int dy = this.y - other.y;  
    return Math.sqrt( dx * dx + dy * dy ); 
  }
  public static void main(String[] args) {
    Point a = new Point(2, 3); 
    Point b = new Point(-1, -6); 
    System.out.println( a.distanceTo( b ) ); 
    System.out.println( b.distanceTo( a ) ); 
  }
}

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

public class Circle {
  private Point center;
  private int radius;
  public Circle(Point center, int radius) {
    this.center = center; 
    this.radius = radius; 
  }
  public double area() {
    return Math.PI * Math.pow( this.radius , 2 ); 
  }

}

Types: 

  (a) primitive types       numbers (int, double, ...)
                            characters 
                            booleans

  (b) user-defined types    Scanner BigDecimal String 

Variables have types. 

Today: arrays, ArrayList's.

int a = 3;

An array is a sequence of values of the same type. 

Using the name and an index you can get to the individual values. 

An array has a size. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> int[] a; // declaration
> a = new int[6]
{ 0, 0, 0, 0, 0, 0 }
> a.length
6
> a[2]
0
> a[2] = 4
4
> a
{ 0, 0, 4, 0, 0, 0 }
> a[5] = 12
12
> a
{ 0, 0, 4, 0, 0, 12 }
> a[6] = 3 
java.lang.ArrayIndexOutOfBoundsException
> a
{ 0, 0, 4, 0, 0, 12 }


The size of an array is fixed. 

Let's redo E6.6 such that it remembers all the numbers and sorts them at the end.  

import java.util.Scanner; 
import java.util.Arrays; 

public class Talk {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);  
    System.out.println("Type: "); 
    String line = in.nextLine(); 
    int[] numbers; 
    numbers = new int[0]; 
    while (! line.equals("bye")) {
      int n = Integer.parseInt( line ); 
      numbers = Arrays.copyOf(numbers, numbers.length + 1); 
      numbers[numbers.length - 1] = n; 
      System.out.println( Arrays.toString( numbers ) ); 
      System.out.println("Type: "); 
      line = in.nextLine(); 
    }
  }
}