Howdy. 

1. Introduction

Java programs are made out of classes.

There are rules. 

Names of classes: nouns that start with uppercase. 

class Exercise {
  public static void main(String a[]) {
    System.out.println("Oops."); 
  }
}

2. Using Objects

3. Implementing Classes

With classes we model things in Java. 

Classes are also containers of useful stuff. 

Let's look at Lab 03 and Homework 03:

// A Point is a pair of numbers (coordinates, x and y)
// A Point can tell how far it is from another point
public class Point {
  // write the model here 
  public static void main(String[] args) {
    Point a, b; 
    a = new Point(1, 1); 
    b = Point.origin;
    System.out.println(b.distanceTo(a)); // 1.4142... 
    Point c = new Point(); // creates another point, in origin
    System.out.println( c.diatance(b) ); // 0
  }
}

Here's the answer:

// A Point is a pair of numbers (coordinates, x and y)
// A Point can tell how far it is from another point
public class Point {
  // write the model here 
  private int x, y; // these instance variables automatically initialized to 0 (zero)
  public Point() {
    this(0, 0);     
  }
  public static Point origin = new Point(); 
  public Point(int eks, int y) {
    x = eks;
    this.y = y;
  }
  public double distanceTo(Point other) {
    double answer; 
    double dx = this.x - other.x; 
    double dy = this.y - other.y; 
    answer = Math.sqrt( dx * dx + dy * dy );
    return answer; 
  }
  public static void main(String[] args) {
    Point a, b; 
    a = new Point(1, 1); 
    b = Point.origin;
    System.out.println(b.distanceTo(a)); // 1.4142... 
    Point c = new Point(); // creates another point, in origin
    System.out.println( c.distanceTo(b) ); // 0
  }
}

Can you model Line, Triangle, Circle? 

What is a Triangle? Three points. 

How can I calculate the arwe of a triangle from the three points? 

Heron's formula. 

import java.awt.*; 

public class Circle {
  private int x, y, r;
  private Color c;
  public Circle(int x, int y, int r, Color c) {
    this.x = x;
    this.y = y;
    this.r = r; 
    this.c = c; 
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(x - r, y - r, 2 * r, 2 * r);
    g.setColor(Color.BLACK);
    g.drawOval(x - r, y - r, 2 * r, 2 * r);
  }
}

How dop I create Circles of various sizes and colors and place them...

import javax.swing.*;
import java.awt.*;

public class Circles extends JComponent {
  Circle a, b, c; 
  public Circles() {
    this.a = new Circle(100, 100, 30, new Color(255, 200, 150));  
    this.b = new Circle(400, 300, 80, new Color( 55, 200, 250));  
    this.c = new Circle(200, 220, 70, new Color(155, 100, 150));  
    
  }
  public void paintComponent(Graphics g) {
    this.a.draw(g);    
    this.b.draw(g);    
    this.c.draw(g);    
}
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setVisible(true); 
    f.setSize(500, 500); 
    f.add(new Circles()); 
  }
}

import java.awt.*; 

public class Circle {
  private int x, y, r;
  private Color c;
  public Circle(int x, int y, int r, Color c) {
    this.x = x;
    this.y = y;
    this.r = r; 
    this.c = c; 
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(x - r, y - r, 2 * r, 2 * r);
    g.setColor(Color.BLACK);
    g.drawOval(x - r, y - r, 2 * r, 2 * r);
  }
}

Joel Hudson attendance for first lecture

https://www.cs.indiana.edu/classes/a202-dger/sum2010/zo.pdf

https://www.cs.indiana.edu/classes/c212-dgerman/fall2017/lab03.html

--