Pascal asked about the last problem on Homework Four. 

I said this program starts from the program you have to prepare for tomorrow. 

Then we went and developed, in class, the minute paper program for tomorrow:

import java.util.*; 
import java.io.*; 

class One {
  public static void main(String[] args) throws Exception {
    
    Scanner pascal = new Scanner(new File( args[0] )); 
    int countLines = 0;
    int countTokens = 0;    
    while (pascal.hasNextLine()) {
      String line = pascal.nextLine(); 
      Scanner rctmpx = new Scanner(line); 
      while (rctmpx.hasNext()) {
        String token = rctmpx.next(); 
        countTokens += 1; 
        System.out.println("   " + countTokens + ". " + token); 
      } 
      countLines += 1; 
      System.out.println( countLines + ". (" + line + ")"); 
    } 

  }
}

This program was run with a data file:

[kbuckner@silo 0710]$ pwd
/u/kbuckner/0710
[kbuckner@silo 0710]$ ls -ld haiku.txt
-rw------- 1 kbuckner students 75 Jul 10 12:21 haiku.txt
[kbuckner@silo 0710]$ cat haiku.txt
I will

    write

  something.

    This

is it.
[kbuckner@silo 0710]$

We have run this program on both Windows and silo. 

Here's how it runs: 

[kbuckner@silo 0710]$ pwd
/u/kbuckner/0710
[kbuckner@silo 0710]$ ls -ld haiku.txt
-rw------- 1 kbuckner students 75 Jul 10 12:21 haiku.txt
[kbuckner@silo 0710]$ cat haiku.txt
I will

    write

  something.

    This

is it.
[kbuckner@silo 0710]$ ls -ld One.java
-rw------- 1 kbuckner students 617 Jul 10 12:23 One.java
[kbuckner@silo 0710]$ cat One.java
import java.util.*;
import java.io.*;

class One {
  public static void main(String[] args) throws Exception {

    Scanner pascal = new Scanner(new File( args[0] ));
    int countLines = 0;
    int countTokens = 0;
    while (pascal.hasNextLine()) {
      String line = pascal.nextLine();
      Scanner rctmpx = new Scanner(line);
      while (rctmpx.hasNext()) {
        String token = rctmpx.next();
        countTokens += 1;
        System.out.println("   " + countTokens + ". " + token);
      }
      countLines += 1;
      System.out.println( countLines + ". (" + line + ")");
    }

  }
}
[kbuckner@silo 0710]$ javac One.java
[kbuckner@silo 0710]$ java One haiku.txt
   1. I
   2. will
1. (I will)
2. ()
   3. write
3. (    write                 )
4. (        )
   4. something.
5. (  something.)
6. ()
   5. This
7. (    This)
8. ()
   6. is
   7. it.
9. (is it.)
[kbuckner@silo 0710]$

So it should be clear how to finish this problem now. 

Stephen asked about the specifics of the first three problems on Homework Four. 

I said there is a program in Lecture Thirteen: 

import java.util.Scanner;

class Arrays {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int[] numbers; // declaration
    numbers = new int[0];
    System.out.println( java.util.Arrays.toString( numbers ) );
    System.out.print("type: ");
    String line = in.nextLine();
    while (! line.equals("bye")) {
      int number = Integer.parseInt( line );
      int[] temporary = java.util.Arrays.copyOf(numbers, numbers.length + 1);
      temporary[temporary.length - 1] = number;
      numbers = temporary;
      System.out.println( java.util.Arrays.toString( numbers ) );
      System.out.print("type: ");
      line = in.nextLine();
    }

    /*java.util.*/Arrays.sort( numbers );

    System.out.println( java.util.Arrays.toString( numbers ) );
  }
  // your code here ...
  public static void sort(int[] a) {
    System.out.println("Hey, sorting is going to happen here.");
  }
}

Notice that I provided a sort method (unfinished) above. 

Everything else works because it's taken from java.util.Arrays except sort where the java.util part is commented out. 

Your job is to produce the three methods and use them by commenting out (or deleting) the java.util references in the code. 

For sorting I provided the following suggestion:

http://www.cs.indiana.edu/classes/c212-dgerman/spr2012/classNotes/simple.html

We discussed this in class and we determined this is a tail-recursive method (not that it matters!)

We'll discuss magic squares, two dimensional arrays and array lists of array lists tomorrow. 

See you in lab. 

--