Lecture Thirteen: July 9, 2013

I posted a midterm solution at:

http://silo.cs.indiana.edu:8346/c212/sum2013/midterm.phps

I am almost done grading it. 

I will e-mail you the midterm grades individually tonight. 

I will bring back and return the midterms tomorrow. 

Homework Four will be posted tonight will be due Mon. 

For the next three labs we won't submit anything in OnCourse. 

There's a secure on-line repository on-line at: 

https://html.soic.indiana.edu/~tblgrant/sum2013/c212/

In my e-mail tonight I will ask you to please confirm all your work is there. 

There's a new resource we will start using next week in addition to the text we have:

https://www.cs.indiana.edu/classes/c212-dgerman/spr2013/classNotes/gfmk.pdf

int n; 

int[] n; // declaration 

int n[]; 

n = new int[10]; // allocation 

n[3] = -2; // initialization 

Here's the program for tomorrow's minute paper: 

import java.util.*;

class Five {
  public static void main(String[] args) {
    Scanner a = new Scanner(System.in);
    System.out.print("Enter: ");
    String line = a.nextLine();
    int[] numbers = new int[0];
    System.out.println( Arrays.toString ( numbers ) );
    while (! line.equals("bye")) {
      numbers = Arrays.copyOf(numbers, numbers.length + 1);
      numbers[numbers.length - 1] = Integer.parseInt( line );
      System.out.println( Arrays.toString( numbers ) );
      System.out.print("Enter: ");
      line = a.nextLine();
    }
    System.out.println("Array unsorted: " + Arrays.toString(numbers));
    Arrays.sort( numbers );
    System.out.println("Array sorted: " + Arrays.toString(numbers));
  }
}

The program above also defines 3/5 of Homework Four. 

Here's the same program implemented with ArrayLists: 

import java.util.*;

class Six {
  public static void main(String[] ags) {
    Scanner a = new Scanner(System.in);
    System.out.print( "Enter: " );
    String line = a.nextLine();
    ArrayList<Integer> numbers = new ArrayList<Integer>();
    System.out.println( numbers );
    while (! line.equals( "bye" )) {
      numbers.add( Integer.parseInt( line ) );
      System.out.println( numbers );
      System.out.print( "Enter: " );
      line = a.nextLine();
    }
    Collections.sort( numbers );
    System.out.println( numbers );
  }
}

Knowing either one of these for tomorrow will give you 100% points of attendance. 

--