Grade is: 100 -c where is c is the cost of fixes. 

You can get back between 1/3 and 1/2 after the lab. 

Examples: 

 80 86 90
 90 93 95
 50 66 75
  0 33 50 

Make-ups? Adjustments? 

http://silo.cs.indiana.edu:8346/cgi-bin/spr2015/schedule

Four exams:

(a) read code 

(b) write code

http://www.cs.indiana.edu/classes/c212/fall2011/whatsnew.html

Homework Eight

will be about 10-12 problems
these are typical problems
for every problem solution will be provided
it will be provided as an interactive template

There will also be one problem without solution. 

Then all the makeups for the midterm will be from this set. 

DrJava

BlueJ

What kind of approaches have I seen on the exam:

(a) people emulated Homework Three

(b) same without storing the numbers

-- one main, maybe no other methods

(c) lots of methods invoked from a loop in main 

-- issues: non-static methods called from main 

(d) store the numbers and sort them 

-- if array has size zero, no data

-- otherwise easy to identify max and min

(e) controlling what the user inputs

(f) some (between 2-5) purely object oriented approaches 

(g) what's the difference between expecting floats and reading lines

(h) using user-defined types like in C211 (ListOfString, etc.)

(i) ...

These will be summarized in the notes I post for today's class. 

Exercise:

Let's suppose you are given a sequence of numbers, integers. 

     3 6 6 3 3 3 3 7 2 5 5 5 5 6 3 4 4

Let's define a run to be a sub-sequence of numbers with the same value.

How could we identify runs in our input and specifically the longest one. 

     (3) (6 6) (3 3 3 3) (7) (2) (5 5 5 5) (6) (3) (4 4)

Which one is the longest here? 

Options: the first, the last, the one with largest number, etc. 

What if I now want to sort these runs?

What is your first thought about approaching this problem? 

Time: 5 minutes. 

Things that come to mind: 

(a) work with an ArrayList<ArrayList<Integer>>

(b) define a Frequency kind of object

Basically I claim the first step is to model what a Run is. 

class Run {
  int start, size, value;
}

Now I can use an ArrayList<Run> to store them. 

      3   6 6   3 3 3 3   7   2   5 5 5 5   6   3   4 4
--------------------------------------------------------------
      0   1 2   3 4 5 6   7   8   9101112  13  14  1516

     (3) (6 6) (3 3 3 3) (7) (2) (5 5 5 5) (6) (3) (4 4)

Encoded as follows:

   (( 0, 1, 3) 
    ( 1, 2, 6) 
    ( 3, 4, 3) 
    ( 7, 1, 7)
    ( 8, 1, 2) 
    ( 9, 4, 5)
    (13, 1, 6)
    (14, 1, 3)
    (15, 2, 4))

Sort it: 

  - specify criteria

  - use Comparable or Comparators 

Here's an example of sorting:

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

import java.util.*; 

class Program {
  public static void main(String[] args) {
    ArrayList<Student> a = new ArrayList<Student>();  
    a.add(new Student("Laura" ,  8)); 
    a.add(new Student("Leslie", 12)); 
    a.add(new Student("Alex"  , 12)); 
    a.add(new Student("Chris" , 12)); 
    a.add(new Student("Larry" ,  8)); 
    a.add(new Student("Adam"  , 12)); 
    System.out.println( a );
    Collections.sort( a ); 
    System.out.println( a );
    
  }
}

Run this to get:

Welcome to DrJava.  Working directory is C:\Users\dgerman
> run Program
[Laura:8, Leslie:12, Alex:12, Chris:12, Larry:8, Adam:12]
[Laura:8, Larry:8, Leslie:12, Alex:12, Chris:12, Adam:12]


What if we want other orders? 

--