1. Stage 03
 2. Homework 12
 3. Lab 12

 1. Assume you finished Stage 02. Post a link. 

    Add all the remaining .jsp and .java files, compile, post link.

    Tao's lessons on what to do and what not to do: 

    (a) keep only one server around if you don't need more than one

    (b) don't set up variables automatically if you don't need them 

    (c) compile with the same version of Java as Tomcat 

    (d) become manager and save the world

    (e) provide the links to the two stages

        http://silo.cs.indiana.edu:11836/qotd/model/test
        
        http://silo.cs.indiana.edu:11836/qotd/random  

Courtesy Maazin: 

        Collections.sort(b, (Box one, Box two) -> {
            return one.weight - two.weight;  // lambda expression 
        });

Special Topic 19.4

https://www.cs.indiana.edu/classes/c212-dgerman/fall2016/resources/rctmpx/5317.html

https://stackoverflow.com/questions/21970719/java-arrays-sort-with-lambda-expression

For the other problem in Homework 12:

What's New? Oct 25

Also recall the solution posted for Lab 10 (due to Feng Lou)

http://silo.cs.indiana.edu:8346/c212/fall2018/lab10sr.phps

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Pair<String, Integer> a = new Pair<String, Integer>()
Static Error: No constructor in Pair<String, Integer> matches this invocation
    Arguments: ()
    Expected return type: Pair<String, Integer>
    Candidate signatures: Pair(String, Integer)
> Pair<String, Integer> a = new Pair<String, Integer>("Ben", "35")
Static Error: No constructor in Pair<String, Integer> matches this invocation
    Arguments: (String, String)
    Expected return type: Pair<String, Integer>
    Candidate signatures: Pair(String, Integer)
> Pair<String, Integer> a = new Pair<String, Integer>("Ben", 35)
> a
(Ben, 35)
> Pair<Pair<String, Integer>, Integer> b; 
> b = new Pair<Pair<String, Integer>, Integer>(a, 102)
((Ben, 35), 102)


public class Pair<T, S> {
  T first;
  S second; 
  public Pair (T first, S second) {
    this.first = first; 
    this.second = second; 
  } 
  public T getFirst() {
    return this.first; 
  }   
  public S getSecond() {
    return this.second; 
  } 
  public String toString() {
    return "(" + this.getFirst() + ", " + this.getSecond() + ")"; 
  } 
}

import java.text.*;
import java.util.*;

interface Vertailukelpoinen<T> { // in honor of Linus Torvalds
  int vertaa(T other);
}

class Student implements Vertailukelpoinen<Student> {
  String name;
  int age;
  Student(String name, int age) {
    this.name = name;
    this.age = age;
  }
  public int vertaa(Student other) {
    if (this.age < other.age) return -1;
    else if (this.age > other.age) return 1;
    else return 0;
  }
  public String toString() {
    return name + ":" + age;
  }
}

class One {
  public static void main(String[] args) {
    Student[] students = new Student[6];
    students[0] = new Student("Alice" , 4);
    students[1] = new Student("Bob"   , 8);
    students[2] = new Student("John"  , 6);
    students[3] = new Student("Tom"   , 7);
    students[4] = new Student("Leslie", 8);
    students[5] = new Student("Alex"  , 5);

    System.out.println( Two.toString(students) );
    Two.sort( students );
    System.out.println( Two.toString(students) );
  }
}

class Two {

  static <T extends Vertailukelpoinen<T>> void sort(T[] a) {
    boolean sorted;
    do {
      sorted = true;
      for (int i = 0; i < a.length - 1; i++) {
        if ((a[i]).vertaa(a[i+1]) > 0) {
          sorted = false;
          T temp = a[i];
          a[i] = a[i+1];
          a[i+1] = temp;
        }
      }
      System.out.println( Two.toString(a) );
    } while ( ! sorted );
  }

  static <E> String toString(E[] a) {
    String result = "";
    for (E e : a)
      result += e + ", ";
    return result.substring(0, result.length() - 2);
  }

}
-bash-4.1$ javac One.java
-bash-4.1$ java One
Alice:4, Bob:8, John:6, Tom:7, Leslie:8, Alex:5
Alice:4, John:6, Tom:7, Bob:8, Alex:5, Leslie:8
Alice:4, John:6, Tom:7, Alex:5, Bob:8, Leslie:8
Alice:4, John:6, Alex:5, Tom:7, Bob:8, Leslie:8
Alice:4, Alex:5, John:6, Tom:7, Bob:8, Leslie:8
Alice:4, Alex:5, John:6, Tom:7, Bob:8, Leslie:8
Alice:4, Alex:5, John:6, Tom:7, Bob:8, Leslie:8
-bash-4.1$

What is Big Oh complexity? 

f(0) = 1
f(1) = 1
f(n) = f(n-1) + f(n-2) 

f(40)