Java programs are made of classes. 

Classes contain: 

(a) static members

(b) non-static members

(c) constructors

Here's a random example:

class Something {
  int a; // instance variable 
  String b; // instance variable 
  Something(int a, String b) { // constructors, two parameters
    this.a = a;
    this.b = b;
  }
  void fun() {
    double c = 3.54; // local variable 
    System.out.println( c ); 
    System.out.println( this.a ); 
    System.out.println( this.b.length() ); 
    System.out.println( Something.c ); // false    
  }
  static boolean c; // static variable 
  public static void main(String[] args) {
     Something joe = new Something(5, "what");
     joe.fun(); 
  }
}

Please refer to static member via the class name. 

Please refer to instance members via the reference to the instance holds them. 

With this information let's write some programs: 

1. Let's model points in the plane. 

2. Let's model lines in the plane. 

3. Let's model triangles.

4. Let's model circles, rectangles. 

class Point {
  int x, y;
  Point(int x, int y) {
    this.x = x;
    this.y = y;
  }
  Point() {
    this(0, 0); // calls the peer constructor 
  }
  double distanceTo(Point p) {
    int dx = this.x - p.x;
    int dy = this.y - p.y; 
    return Math.sqrt( dx * dx + dy * dy ); 
  }
  public static void main(String[] args) {
    Point a = new Point(4, 5);  
    System.out.println( Point.origin.distanceTo( a ) ); // 6.403124... 
  }
  static Point origin = new Point(); 
}

This looks good, how about lines? 

class Line {
  Point a, b; 
  Line(Point a, Point b) {
    this.a = a;
    this.b = b;
  }
  double length() {
    return this.a.distanceTo(this.b); 
  }
  public static void main(String[] args) {
    Line a = new Line( new Point(3, 0), new Point(0, 4) ); 
    System.out.println( a.length() ); 
  }
}

Here's the Triangle class:

class Triangle {
  Line a, b, c;
  Triangle(Point a, Point b, Point c) {
     this.a = new Line(a, b);
     this.b = new Line(a, c);
     this.c = new Line(c, b);
  }
  double area() {
    // http://en.wikipedia.org/wiki/Heron%27s_formula
    double a = this.a.length(); 
    double b = this.b.length(); 
    double c = this.c.length(); 
    double s = 0.5 * (a + b + c); 
    return Math.sqrt( s * (s - a) * (s - b) * (s - c) ); 
  }
  public static void main(String[] args) {
    Triangle a = new Triangle( Point.origin, new Point(0, 3), new Point(4, 0) ); 
    System.out.println( a.area() ); // 6.0
  }
}

How about a Circle?

class Circle {
  Point location; // center 
  double radius;
  Circle(Point location, double radius) {
    this.location = location;
    this.radius = radius; 
  }
  double area() {
    return Math.PI * Math.pow( this.radius, 2 );  
  }
  public static void main(String[] args) {
    Circle c = new Circle( new Point(1, 2), 3 ); 
    System.out.println( c.area() ); // 28.27
  }
}

Here's a Rectangle:

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

Do you remember arrays? 

How about ArrayLists? 

class Kevin {
  public static void main(String[] args) {
     Object[] a = new Object[6];  
     a[0]= new Point(1, 2); 
     a[1]= new Circle(new Point(3, -2), 7); 
     a[2] = new Line( Point.origin, new Point(-1, -1) );

     System.out.println( java.util.Arrays.toString( a ) ); 
  }
}

Compile and run:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\Shikun
> run Kevin
[Point@879c2a, Circle@11dae99, Line@1b1df2e, null, null, null]


See you on Wed. 

--