Java programs are made out of classes. 

No classes -- no programs.

Classes can hold static and non-static members. 

Examples: 

  Math.sqrt(...) static method in class Math in package java.lang

  Math.PI it's a constant but it has a name and is not a method

http://en.wikipedia.org/wiki/Indiana_Pi_Bill

Non-static members form a blueprint, a vision. 

If you instantiate the class you get an object. 

Its structure is given by the blueprint.

Instance members (variables and methods) belong to objects. 

For convenience we have constructors. 

Define a class Circle. 

  A Circle has a center and a radius. 

  The center is a Point. 

    A Point is a pair of two numbers. 

    Maybe Points need to be smart.

  The radius is a number. 

  A Circle needs to know its area ( pi * radius squared). 

Define a class Rectangle. 

  A Rectangle is a Point (for the location) plus a width and a height. 

  A Rectangle is supposed to be able to calculate and report its area (width * height). 

Now create some of these and put them in an array please. 

--

Teamwork (11:54 - 12:00)

--

Recipe to define a class to model something:

1. define a class with appropriate name

2. identify the state (instance variables) in the objects

3. define a constructor

4. define instance methods that you might need

5. here and after every step: test your code/design 

class Point {
  double x; // on the horizontal increasing from left to right 
  double y; // on the vertical increasing as you go down 
  Point(double x, double y) {
    this.x = x;
    this.y = y; 
  }
  double distanceTo(Point other) {
    double dx = this.x - other.x;
    double dy = this.y - other.y;
    return Math.sqrt( dx * dx + dy * dy ); 
  }
}

class Example {
  public static void main(String[] ags) {
    Point a;
    a = new Point(2, 3); 
    Point b = new Point(4, 1); 
    System.out.println( a.distanceTo(b) ); // 2 * 1.4142... == 2.8284...
    System.out.println( b.distanceTo(a) ); // same 
    System.out.println( a.distanceTo(a) ); // 0.0 
    System.out.println( b.distanceTo(b) ); // 0.0 
  }
}

Next we put this together: 

class Point {
  double x; // on the horizontal increasing from left to right 
  double y; // on the vertical increasing as you go down 
  Point(double x, double y) {
    this.x = x;
    this.y = y; 
  }
  double distanceTo(Point other) {
    double dx = this.x - other.x;
    double dy = this.y - other.y;
    return Math.sqrt( dx * dx + dy * dy ); 
  }
}

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

class Rectangle {
  double width;
  double height;
  Point center; 
  Rectangle(double width, double height, Point center) {
    this.width = width;
    this.height = height;
    this.center = center;
  }
  double area() {
    return this.width * this.height;  
  }
}

class Example {
  public static void main(String[] ags) {
    Point a;
    a = new Point(2, 3); 
    Point b = new Point(4, 1); 
    System.out.println( a.distanceTo(b) ); // 2 * 1.4142... == 2.8284...
    System.out.println( b.distanceTo(a) ); // same 
    System.out.println( a.distanceTo(a) ); // 0.0 
    System.out.println( b.distanceTo(b) ); // 0.0 
    Circle c = new Circle(2, b);
    System.out.println( c.area() ); // 4 * 3.141592... == 12.567368... 
    Rectangle d = new Rectangle(3, 4, b); 
    System.out.println( d.area() ); // 12.0
    Circle[] circles = new Circle[3]; 
    circles[0] = c;
    circles[1] = new Circle(2, a); 
    circles[2] = new Circle(3, new Point(-1, -2)); 
    System.out.println( java.util.Arrays.toString( circles ) );    

    Rectangle[] rectangles = new Rectangle[4]; 
    rectangles[0] = d;
    rectangles[1] = new Rectangle(2, 3, b); 
    rectangles[2] = new Rectangle(4, 2, new Point(10, -6)); 
    rectangles[3] = new Rectangle(3, 5, new Point(-4,  2)); 
    System.out.println( java.util.Arrays.toString( rectangles ) );    
    
    // how I create an array in which I can put two circles and three rectangles? 
    
  }
}

We will start discussing that in lab. 

--