Ben Chun Aarani Peter F Peter W Grant Sai Chase 
Michael Nariman Murun Dustin Yuying Zach Jiongran 
JeVante Stephen K Daohui Emma Young Hwan Sunghyun 
Qi Namit Mary Stephen N

(a) the class extension mechanism 

(b) this week we start writing code for the project

public class Horse {
  
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a 
> a
null
> a = new Horse()
Horse@50b9f953


public class Horse {
  public void talk() {
    System.out.println("Howdy.");  
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a
Horse@de131f3
> a.talk()
Howdy.
> Horse b = new Horse()
> b
Horse@73a0c1b
> b.talk()
Howdy.


https://prodimage.images-bn.com/pimages/9780772075727_p0_v1_s550x406.jpg

----------------------------------------------------------------------------

public class Horse {
  public void talk() {
    System.out.println("Howdy.");  
  }
}

// Unicorn = Horse U { extra, features, ... } 
// (Unicorn extends and inherits from Horse)

public class Unicorn extends Horse {
  
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a.talk()
Howdy.
> Unicorn b = new Unicorn()
> b
Unicorn@574e1175
> b.talk() // by inheritance 
Howdy.


--(inheritance)-------------------------------------------------------------

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> Unicorn b = new Unicorn()
> Horse c = new Unicorn() // here 
> Unicorn d = new Horse() 
Static Error: Bad types in assignment: from Horse to Unicorn


--(polymorphism)-------------------------------------------------------------

// Unicorn = Horse U { horn } 

public class Unicorn extends Horse {
  public void sing() {
    System.out.println("La, la, la... ");  
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Unicorn b = new Unicorn()
> b.talk()
Howdy.
> b.sing()
La, la, la... 
> Horse c = new Unicorn()
> c.talk()
Howdy.
> c.sing()
Static Error: No method in Horse has name 'sing'
> ((Unicorn)c).sing()
La, la, la... 


Note that the kinds of things you can do to the object are limited by the 
type of the reference (the remote). 

public class Horse {
  public void talk() {
    System.out.println("Howdy.");  
  }
}

// Unicorn = Horse U { sing, talk } 

public class Unicorn extends Horse {
  public void sing() {
    System.out.println("La, la, la... ");  
  }
  public void talk() {
    System.out.println("Bonjour.");  
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a.talk()
Howdy.
> Unicorn b = new Unicorn()
> b.talk()
Bonjour.
> Horse c = new Unicorn()
> c.talk()
Bonjour.
> c
Unicorn@701aef3a


--(dynamic method lookup)---------------------------------------------------

import javax.swing.JFrame;
  
public class Tuesday {
  public static void main(String[] args) {
    JFrame a = new JFrame();  
    System.out.println( a ); 
    a.setVisible(true); 
    a.setSize(300, 400); 
  }
}

--

Stage 02 Project: Draw a BST. 

https://docs.oracle.com/javase/tutorial/reallybigindex.html

https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html

--

public class Point {
  int x, y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
}

--

import java.awt.Graphics;
import java.awt.Color; 

public class Circle {
  Point center; 
  int radius; 
  Color color; 
  public Circle(Point c, int r, Color color) {
    this.center = c; 
    this.radius = r;
    this.color = color; 
  }
  public void draw(Graphics g) {
    // https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html#drawOval-int-int-int-int- 
    g.setColor(this.color); 
    g.fillOval(this.center.x - this.radius, this.center.y - this.radius, this.radius * 2, this.radius * 2); 
    g.setColor(Color.BLACK); 
    g.drawOval(this.center.x - this.radius, this.center.y - this.radius, this.radius * 2, this.radius * 2); 
  }
}

--

import javax.swing.JComponent; 
import java.awt.Graphics; 
import java.awt.Color; 

public class Screen extends JComponent {
  int count; 
  Circle c = new Circle(new Point(0, 0), 
                        45,
                        new Color((float)(Math.random() * 0.5 + 0.5), 
                                  (float)(Math.random() * 0.5 + 0.5), 
                                  (float)(Math.random() * 0.5 + 0.5)) );
  // the talk we inherit is called paintComponent(...)
  public void paintComponent(Graphics g) {
    System.out.println(++this.count);  
    this.c.draw( g ); 
  }
}

--

import javax.swing.JFrame;
  
public class Tuesday {
  public static void main(String[] args) {
    JFrame a = new JFrame();  
    System.out.println( a ); 
    a.setVisible(true); 
    a.setSize(300, 400); 
    a.add(new Screen()); 
  }
}

--

See you in lab.