Welcome to Spring!

Welcome Danielle, Michael, Erin, Haleigh, Brian, 
Minh, Grant, Vinayak, Chen, Shikun, Mahamat, Connor,
Phoebe, Nick Palumbo, Brandon Lee, Joe Topp, Kevin, 
Griffin, Ben, Shane. Nick Palmer.  

C211 was more uniform. 

C212 variety of backgrounds (including already existing knowledge of Java): huge. 

For this reason instruction differentiated. 

Result: slow. 

Midterm exams: 78 average design, 74 for the implementations. 

Raw scores: 100 - c where c is the cheapest fix to your written test. 

c is subjective but meaningful: local/global minimum that you're seeking. 

Smallest number that preserves the design (your committment). 

Adjustments to the scores:

  depending on the quality of your lab reports 

  you can get back 1/3 to 1/2 of points lost (c) 

Examples: 

   Raw   Average report   Excellent report 

   70         80               85

   40         60               70 

    0         33               50 

I would like to post adjustments after briefly talking to everyone. 

Make ups are also possible: no deadline, no limit.

Four exams: 

(a) read code

(b) write code

(c) design programs made of more than one class

(d) variation on the project

What about make ups of (b)? 

I want the make up to be useful, reliable, predictable. 

Homework Eight: 

  collection of 12-18 problems

  with solutions posted (except one)

Solutions will be posted as interactive templates. 

Interactive templates are like watching a game in slow motion.

An entire game in slow motion: never.

Replay of questionable goal tending play: very useful, interesting. 

Use my templates as you want to use them. 

Make up your own solutions (ignore templates) or study templates. 

This list of problems is the cookbook. 

Make up midterm: random (negotiable) problem from Homework Eight. 

Add to the cookbook the midterm problem and the practice midterm problem. 

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

I promise to add more hours or post them in advance.

Midterm Exam: 

(a) emulated homework three 

(b) some did not store numbers

(c) sort the stored numbers

(d) use methods (static methods with main)

(e) object-oriented solutions (instance methods, objects created in main) 

(f) recursive solutions (including a recursive main)

(g) solutions with inheritance on the exam (ListOfFrequency etc.) 

(h) ?

The exam: 

  design 

  implementation 

We will add UML to the set of design tools soon. 

We will use the Design Patterns book for the project. 

If you can't solve a problem you won't be able to write a program for it. 

So first we need to internalize it by working out an example. 

Problem: suppose you get a list numbers from user.

  1 1 5 3 3 3 4 6 6 8 8 8 7 7 1 5 5 5 

A run is a sequence of numbers with the same value. 

Identify the runs in the sequence. 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)

Identify the longest run.

Find a criterion where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
            -------
Find a criterion where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
                              -------
Find a criterion (or two) where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
                                                -------
Five minutes (11:50am-11:55am). 

Problem: suppose you get a list numbers from user.

  1 1 5 3 3 3 4 6 6 8 8 8 7 7 1 5 5 5 

A run is a sequence of numbers with the same value. 

Identify the runs in the sequence. 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)

What's the first thing you need to work out as you approach this problem? 
           -----------
Thoughts: 

  (a) describe specific ways in which the output is unique 

  (a) choose a data representation for a run (define Run) 

--

  (a) use an array list of array lists of integers

import java.util.*; 

//  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)

class Program {
  public static void main(String[] args) {
    ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();  
    System.out.println( a ); 
    ArrayList<Integer> run = new ArrayList<Integer>(); 
    run.add(1); 
    run.add(1); 
    a.add(run); 
    run = new ArrayList<Integer>(); 
    run.add(5); 
    a.add(run); 
    run = new ArrayList<Integer>(); 
    run.add(3); 
    run.add(3); 
    run.add(3); 
    a.add(run); 
    System.out.println( a ); 
  }
}

Run the code above to get:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Program
[]
[[1, 1], [5], [3, 3, 3]]


  (b) use a Frequency kind of object (define what a Run is) 

--

class Run {
  int start, length, value; 
}

Please convert:

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)      <--- what the user should see 
   0 1   2   3 4 5   6   7 8   91011  1213  14  151617
into our new representation. 

  ((0, 2, 1), (2, 1, 5), (3, 3, 3), (6, 1, 4), (7, 2, 6), (9, 3, 8), ...)

Now I have to work out a solution (processing input into the output for this data representation. 

This is the problem in Homework Eight that no solution posted. 

Mahamat says: you have redundant information in your model. I can optimize that.

I say: premature optimization is the root of all evil (Donald Knuth). 

What if we have to sort the runs? 


Find a criterion where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
            -------
Mahamat: longest run has (a) largest size (b) appears first 
                         (a) largest size (b) smallest value 

Find a criterion where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
                              -------
Ben: (a) largest size (b) largest value 

Find a criterion (or two) where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (8 8 8) (7 7) (1) (5 5 5)
                                                -------
Phoebe: (a) largest size (b) most recent 



State a general enough criterion where this is the longest run: 

  (1 1) (5) (3 3 3) (4) (6 6) (5 5 5) (7 7) (1) (8 8 8)
                              -------

Answer: seems harder without including specific values (made of 5s, appears 2nd, or 2nd from end). 

How do we sort collections of complex  entities (objects, runs)? 

Answer: use Comparator<..., ...>'s or implement Comparable<...>. 

--