Ben Chun Mary Murun JeVante Sai Daohui 
Dustin Nariman Zack Emma Qi 
Namit Sunghyun Grant Chase Jiongran Michael 
StephenK PeterF PeterW ... YoungHwan 

Tomorrow: final exam. 

By tonight 10pm submit your review. 

1. Introduction to Java 

In the first chapter I learn how to write a program that reads strings and prints them back. The program 
below reads two sets of names and then writes options on how they could introduce themselves as a married 
couple. 

import java.util.Scanner;

public class ShowMarriedNames_Solution {
   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      String firstName1;
      String lastName1;
      String firstName2;
      String lastName2;
      
      System.out.println("What is the first person's first name?");
      firstName1 = scnr.nextLine();
      System.out.println("What is the first person's last name?");
      lastName1 = scnr.nextLine();
      System.out.println("What is the second person's first name?");
      firstName2 = scnr.nextLine();
      System.out.println("What is the second person's last name?");
      lastName2 = scnr.nextLine();
      System.out.println("Here are some common married-couple names:");
      System.out.println(firstName1 + " " + lastName1 + " and " + firstName2 + " " + lastName2);
      System.out.println(firstName1 + " and " + firstName2 + " " + lastName1);
      System.out.println(firstName1 + " and " + firstName2 + " " + lastName2);
      System.out.println(firstName1 + " and " + firstName2 + " " + lastName1 + "-" + lastName2);
      System.out.println(firstName1 + " and " + firstName2 + " " + lastName2 + "-" + lastName1);
   }
}

On the exam if I select this problem (recall I will choose 3 of the 20 you post) I will ask it
as follows: write a program that will act as shown below (inputs included). 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\chapter01
> run ShowMarriedNames_Solution
What is the first person's first name? Leslie 
What is the first person's last name? Mann 
What is the second person's first name? Judd
What is the second person's last name? Apatow
Here are some common married-couple names:
Leslie Mann and Judd Apatow
Leslie and Judd Mann
Leslie and Judd Apatow
Leslie and Judd Mann-Apatow
Leslie and Judd Apatow-Mann


--

Monday this week I demonstrated a Stage 02: Data Representation. 

0531 I showed Stage 03: I build a graph and worked Stage 03 on it. 

A tree is a graph. So my demo demonstrated the right knowledge. 

Today I want to show Stage 02 and 03 again with Generics. 

19 25 21 17 23

      19  
     /  \
   21    25 
        /
      17
        \
        23  

This is so because in te BlackJack sorting order descending means: 

  21 19 17 23 25

Here's what we came up with in class today: 

--

import javax.swing.JFrame; 

public class Wednesday {
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    a.add(new Screen()); 
    a.setSize(500, 500); 
    a.setVisible(true); 
  }
}

--

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

public class Screen extends JComponent {
  BST<Integer> bst; 
  public Screen() {
    bst = new BST<Integer>();     
    bst.insert(1); 
    bst.insert(3); 
    bst.insert(2); 
    bst.insert(6); 
    bst.insert(4); 
    bst.prepare(250, 50); 
  }
  public void paintComponent(Graphics g) {
    bst.draw(g); 
  }
}

--

import java.awt.Graphics; 

public class BST<T extends Comparable<T>> {
  Node<T> root;
  public BST() { this.root = null; }
  public BST(Node<T> node) { this.root = node; }
  public BST(T value) { this.root = new Node<T>(value); }
  public void insert(T value) {
    if (this.root == null)
      this.root = new Node<T>(value);
    else if (this.root.value().compareTo(value) > 0)
      this.root.left.insert(value);
    else if (this.root.value().compareTo(value) < 0)
      this.root.right.insert(value);
  }
  public String print() {
    if (this.root == null) return "()";
    else return "(" + this.root.print() + ")";
  }
  public String toString() {
    return this.root == null ? "" : this.root + "";
  }
  public void draw(Graphics g) {
    if (root == null) {
      
    } else {
      root.draw(g);  
    }
  }
  public void prepare(int x, int y) {
    if (root != null) root.prepare(x, y);  
  }
}

--

import java.awt.*; 

class Node<T extends Comparable<T>> {
  public void prepare(int x, int y) {
    System.out.println(this.value + " at (" + x + ", " + y + ")"); 
    this.x = x; 
    this.y = y; 
    if (this.left != null) this.left.prepare(x + (int)(Math.random() * 30 - 40), y + 40);  
    if (this.right != null) this.right.prepare(x + (int)(Math.random() * 30 + 10), y + 40);  
  }
  int x, y; 
  T value;
  BST<T> left, right;
  public Node(T value) {
    this.value = value;
    this.left = new BST<T>();
    this.right = new BST<T>();
  }
  public String toString() {
    return this.left + " " + this.value + " " + this.right;
  }
  public T value() {
    return this.value;
  }
  public String print() {
    return this.value + " " + this.left.print() + " " + this.right.print();
  }
  public void draw(Graphics g) {
    g.setColor(Color.WHITE); 
    if (left != null && left.root != null) { left.draw(g); g.drawLine(x, y, left.root.x, left.root.y ); } 
    if (right != null && right.root != null) { right.draw(g); g.drawLine(x, y, right.root.x, right.root.y );  } 
    g.fillOval(x-15, y-15, 30, 30); 
    g.setColor(Color.BLACK); 
    g.drawString(value + "", x, y);  
    g.setColor(Color.WHITE); 
  }
}

--