Some questions to get us started:

(a) What is your model of Homework Nine?

Adrian: notes from class 11/13. 

Brad: my program is my model. 

(b) Do you need to model anything for Homework Nine? 

Yes: Inspector, Run.

(c) How does your model compare with other models? 

I don't have another model, that's the best I can think of, and that's it. 

Remember the notes from Tue. Here are some snapshots:


C:\Users\dgerman\Desktop>java One 6 14
[5, 1, 5, 6, 6, 1, 2, 6, 3, 6, 6, 2, 5, 1]
[5 , 1 , 5 , [6, 6], 1 , 2 , 6 , 3 , [6, 6], 2 , 5 , 1 ]
The max run is: [6, 6]

C:\Users\dgerman\Desktop>java One 6 14
[3, 6, 3, 5, 4, 6, 1, 1, 5, 4, 1, 6, 5, 2]
[3 , 6 , 3 , 5 , 4 , 6 , [1, 1], 5 , 4 , 1 , 6 , 5 , 2 ]
The max run is: [1, 1]

C:\Users\dgerman\Desktop>java One 6 14
[6, 4, 1, 4, 6, 6, 5, 2, 5, 5, 4, 4, 2, 5]
[6 , 4 , 1 , 4 , [6, 6], 5 , 2 , [5, 5], [4, 4], 2 , 5 ]
The max run is: [6, 6]

C:\Users\dgerman\Desktop>javac One.java

C:\Users\dgerman\Desktop>java One 6 14
[6, 5, 2, 1, 5, 5, 6, 6, 4, 2, 4, 2, 5, 4]
[6 , 5 , 2 , 1 , [5, 5], [6, 6], 4 , 2 , 4 , 2 , 5 , 4 ]
The max run is: [6, 6]
 6 5 2 1 5 5 ( 6 6 ) 4 2 4 2 5 4

C:\Users\dgerman\Desktop>

--

Here are two competing models for Run's.

Before we do that let's define something: 

an abstract data type is 

  (a) data                                         instance variables 

plus

  (b) associated operations allowed on it          instance methods 

This sounds like a model, the blueprint in a class. 

First model of Run: 

class Run extends ArrayList<Integer> {
   
}

Is this an abstract data type by the definition. 

If so, can you identify (a) and (b). 

Minute paper:

this is indeed a model and an ADT. But it's loose. 

Run's inherit add from ArrayList<Integer> but that can lead to:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Run a;
> a
null
> a = new Run()
[]
> a.add(5)
true
> a
[5]
> a.add(5)
true
> a
[5, 5]
> a.add(7)
true
> a
[5, 5, 7]


Can you define an add method for Run that preserves integrity. 

How about this:

import java.util.*; 

class Run extends ArrayList<Integer> {
  public boolean add(Integer i) {
    if (this.size() == 0) {
      return super.add(i);
    } else {
      if (i == this.get(0)) {
        return super.add(i);
      } else {
        return false; 
      }
    }
  }
}

So this is one option. 

It works like this:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Run a = new Run()
> a
[]
> a.add(7)
true
> a
[7]
> a.add(4)
false
> a
[7]


I can even simplify this:

import java.util.*; 

class Run extends ArrayList<Integer> {
  public boolean add(Integer i) {
    if (this.size() == 0 || i == this.get(0)) 
      return super.add(i);
    else  
      return false; 
    
  }
}

Here's a competing model for Run:

class Run {
  int start, end; 
  int value; 
  ... // associated instance methods 
}

Compare this model with the previous one. 

Can this one do more or less for us? 

In lab we will discuss hash tables and maps.

http://www.cs.indiana.edu/classes/c212-dgerman/spr2012/whatsnew/horstmannSummary/image002.jpg

Your lab will be to read, implement and summarize chapters 12 and 13 from 

https://www.cs.indiana.edu/~dgerman/sum2012/hfjse.pdf


import java.util.*; 

class Run extends ArrayList<Integer> {
  public boolean add(Integer i) {
    if (this.size() == 0 || i == this.get(0)) {
      super.add(i);
      return ! false;
  } else  
      return false; 
    
  }
}