* mahazuga: Mary Ann
* serepate: Serena
* hgarciah: Henri
* balbakr : Bakr
* ruifan  : Rui
* mzelenin: Matthew
* jnp2    : Jay
* zeyang  : Zejun
  zhang486: Jingyun
  yiwecao : Yiwei
* rthammon: Ryan
* wang686 : Jiaxing
* dweissma: Andrew
* kevcao  : Kevin
* ssalmero: Salmeron, Santiago (TA)
  luo23   : Yawen
* runxzhao: Runxia
* dgerman : German, Dan-Adrian (Primary Instructor)
  creba   : Chris

grade reports have been sent 

import java.util.ArrayList; 

public class Sequence {
  public Sequence longestPrefix() {
    Sequence result = new Sequence();
    for (int i = 0; i < this.size();    ) {
      if (result.size() == 0) 
        result.add(this.get(i++));
      else if (result.get(result.size() - 1) <= this.get(i)) 
        result.add(this.get(i++));
      else break; 
    }
    return result; 
  }
  public Sequence rest() {
    Sequence result = new Sequence();
    int i = 0; 
    for (     ; i < this.size();    ) {
      if (result.size() == 0) 
        result.add(this.get(i++));
      else if (result.get(result.size() - 1) <= this.get(i)) 
        result.add(this.get(i++));
      else break; 
    }
    result = new Sequence(); 
    for (int j = i; j < this.size(); j++) 
      result.add(this.get(j));
    return result; 
  }
  
  private ArrayList<Integer> values; 
  public Sequence() {
    this.values = new ArrayList<Integer>();
  }
  public Sequence(int[] values){ 
    this(); // ha, ha!
    for (int v : values)
      this.values.add( v);
  } 
  public void add(int n) {
    this.values.add(n);
  }
  public String toString() {
    return this.values.toString();
  }
  public static void main(String[] args) {    
    Sequence w = new Sequence( new int[] { 4, 5, 2, 3, 1, 7, 6 } ); 
    // notice how easy it is to initialize a Sequence now
    System.out.println( w ); 
    
    Sequence a = new Sequence( new int[] { 1, 4, 9, 16 } );
    Sequence b = new Sequence( new int[] { 4, 7, 9, 9, 11} );
    
    Sequence c = b.merge(a); 
    
    System.out.println( "merge(" + a + ", " + b + ") = " + c ); 
    
    Sequence d = new Sequence();
    System.out.println( "longest(" + d + ") = " + d.longestPrefix() ); 
    
    Sequence e = new Sequence(new int[] {6, 5, 4, 3, 2, 1});
    System.out.println( "longest(" + e + ") = " + e.longestPrefix() ); 
    
    Sequence f = new Sequence(new int[] {4, 5, 6, 7, 1, 2, 3});
    System.out.println( "longest(" + f + ") = " + f.longestPrefix() ); 
    
    Sequence g = new Sequence(new int[] {1, 2, 2, 3, 4, 5, 5, 6, 7});
    System.out.println( "longest(" + g + ") = " + g.longestPrefix() ); 
    
    Sequence h = new Sequence( new int[] { 8, 2, 3, 1 } ); 
    Sequence i = new Sequence( new int[] { 6, 6, 9, 2, 3, 11 } ); 
    
    System.out.println( h.longestPrefix().merge(i.longestPrefix()) ); 
    // I expect [6, 6, 8, 9]

    System.out.println(h.rest()); // [2, 3, 1]
    System.out.println(i.rest()); // [2, 3, 11]
    
    Sequence j = new Sequence( new int[] { 3, 1, 3, 2, 4, 6, 2, 5, 6, 1 } ); 

    System.out.println( j.sort() ); // [ 1, 1, 2, 2, 3, 3, 4, 5, 6, 6 ]
    System.out.println( j ); // [ 3, 1, 3, 2, 4, 6, 2, 5, 6, 1 ]
    
  }
  public Sequence sort() {
    if (this.size() == 0) return this; 
    else {
      Sequence a = this.longestPrefix(); 
      Sequence b = this.rest(); 
      return a.merge(b.sort()); 
    }
  }
  public int size() {
    return this.values.size();  
  }
  public Integer get(int index) {
    return this.values.get(index); 
  }
  public Sequence merge(Sequence other) {
    Sequence result = new Sequence();  
    if (this.size() == 0) { // host is empty 
      if (other.size() == 0) { // the other sequence also empty
        
      } else { // the other sequence not empty
        for (int i = 0; i < other.size(); i++) 
          result.add(other.get(i)); 
      }
    } else { // host is not empty
      if (other.size() == 0) { // the other sequence is empty 
        for (int i = 0; i < this.size(); i++) 
          result.add(this.get(i)); 
      } else {
        for (int i = 0, j = 0; i < this.size() || j < other.size();   ) {
          if (i < this.size() && j < other.size()) {
            if (this.get(i) < other.get(j)) {
              result.add(this.get(i++));  
            } else {
              result.add(other.get(j++));            
            }
          } else if (i >= this.size()) {
            result.add(other.get(j++));
          } else {
            result.add(this.get(i++));
          }
        }
      }
    }
    return result; 
  }
}

To run the JUnit tutorial:

(a) create a folder

(b) create a folder inside the folder 

(c) take the junit jar file and put it there 

(e) create a set up file with three environment variables

(f) source it so you set the variables for the session

(g) follow the tutorial

https://www.tutorialspoint.com/junit/junit_time_test.htm

[runxzhao@silo C212-Summer]$ pwd
/u/runxzhao/C212-Summer
[runxzhao@silo C212-Summer]$ clear
[runxzhao@silo C212-Summer]$ pwd
/u/runxzhao/C212-Summer
[runxzhao@silo C212-Summer]$ ls -l
total 12
drwx------ 3 runxzhao students   31 Jul  9 14:54 junit-tutorial
-rw------- 1 runxzhao students 1160 Jun 20 12:08 Server.class
-rw------- 1 runxzhao students 1153 Jun 20 12:08 Server.java
-rw------- 1 runxzhao students 1038 Jun 20 12:08 Server$MyHandler.class
drwx------ 2 runxzhao students   36 Jul  9 14:47 software
[runxzhao@silo C212-Summer]$ ls -ld .setup
-rw------- 1 runxzhao students 161 Jul  9 14:49 .setup
[runxzhao@silo C212-Summer]$ cat .setup
JAVA_HOME=/usr/lib/jvm/java-1.8.0
export JAVA_HOME

JUNIT_HOME=~/C212-Summer/software
export JUNIT_HOME

CLASSPATH=$JUNIT_HOME/junit-4.10.jar:.
export CLASSPATH
[runxzhao@silo C212-Summer]$ tree junit-tutorial/
junit-tutorial/
+-- time-test
    +-- MessageUtil.class
    +-- MessageUtil.java
    +-- TestJunit.class
    +-- TestJunit.java
    +-- TestRunner.class
    +-- TestRunner.java

1 directory, 6 files
[runxzhao@silo C212-Summer]$ tree software/
software/
+-- junit-4.10.jar

0 directories, 1 file
[runxzhao@silo C212-Summer]$

--

Question: 

  2.0 and 1.9998  

Are they the same up to two decimal places? 

2.0 - 1.9998 < 0.001 

So shouldn't the answer be yes? 

1.9999999.... - 1.9998 

Fortunately 2.0 admits two representations. 

--

[runxzhao@silo C212-Summer]$ javac Example.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[runxzhao@silo C212-Summer]$ java Example
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-2147483286
[runxzhao@silo C212-Summer]$ cat Example.java
public class Example {
  public static void main(String[] args) {
    int i = 10;
    for (     ; i > 0; i += 1000) {

    }
    System.out.println( i );
  }
}
[runxzhao@silo C212-Summer]$

--

[runxzhao@silo C212-Summer]$ cat One.java
import java.io.File;
import java.util.Scanner;

public class One {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(new File(args[0]));
    int count = 0;
    while (in.hasNext()) {
      String candidate = in.next();
      System.out.println( ++count + ". " + candidate );
    }
  }
}
[runxzhao@silo C212-Summer]$ cat candidates.txt
Kethledge

    Barrett    Barrett

   Kethledge

 Barrett     Barrett    Barrett

 Kavanaugh

Kavanaugh

    Barrett

   Kavanaugh  Kethledge   Kavanaugh
[runxzhao@silo C212-Summer]$ java One candidates.txt
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
1. Kethledge
2. Barrett
3. Barrett
4. Kethledge
5. Barrett
6. Barrett
7. Barrett
8. Kavanaugh
9. Kavanaugh
10. Barrett
11. Kavanaugh
12. Kethledge
13. Kavanaugh
[runxzhao@silo C212-Summer]$ java One cadnidates.txt
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Exception in thread "main" java.io.FileNotFoundException: cadnidates.txt (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.util.Scanner.<init>(Scanner.java:611)
        at One.main(One.java:6)
[runxzhao@silo C212-Summer]$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at One.main(One.java:6)
[runxzhao@silo C212-Summer]$