Attendance for today: 

http://www.cs.indiana.edu/classes/c212-dgerman/fall2012/review.html

Please identify three problems that are too simple for you.

Please identify three problems that are too difficult for you. 

Please e-mail them to me now: dgerman@indiana.edu

For example: 

https://www.cs.indiana.edu/~dgerman/sum2012/c212/studyguideparttwo/image022.jpg

Or indicate its name: Standard Deviation. 

In your e-mail please indicate what other things might be of concern.

Here's another way to look at the midterm review:

http://www.cs.indiana.edu/classes/c212-dgerman/sum2012/midterm.html

On what's new there's a problem that has an error. 

Can you find the error and fix the problem. 

Daniel      Lindsay     JSON 
Justin      Blake       --         Alex S
Staci       Kyle N      --         -- 
Neelan      Erik        Adam K     Dylan K
Max         Artur       --         Kyle C 
Mary Anne   Justin      Adam J     Austin 
--          Yinan       --         Jordan 
Kexin       Scott       Ruifeng    Hang
            Zhichao     Yi         Yunsheng
                                   Maxine

Now: solve P5.8 on this page

https://www.cs.indiana.edu/~dgerman/sum2012/c212/chapterfive/image010.jpg

How do I do it? 

1. Write a program that compiles and runs. 

class Exercise {
  public static void main(String[] args) {
    System.out.println("Whatever."); 
  }
}

2. Take the sentence from the command line. 

class Exercise {
  public static void main(String[] args) {
    System.out.println( java.util.Arrays.toString( args ) ); 
  }
}

It works like this: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Exercise
[]
> java Exercise How is this for a midterm exam?
[How, is, this, for, a, midterm, exam?]


3. Print it where you process every word. 

class Exercise {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i = i + 1) {
      System.out.println( Exercise.scramble( args[i] ) );  
    }
  }
  public static String scramble(String word) {
    String first = word.substring(0, 1); 
    String last = word.substring(word.length() - 1); 
    String middle = word.substring(1, word.length() - 1); 
    return last + middle + first; 
  }
}

4. Refine the processing to do what they want. 

Plan: isolate the middle, make sure word has a middle. 

Get two random numbers, make sure they're not the same. 

Assume they are i and j and the middle is the middle. 

Make sure that i has the smaller value. 

My answer is: first                      + // "h" 
              middle.substring(0  , i  ) + // "o"
              middle.substring(i  , i+1) + // "u" <--(first letter to swap)--
              middle.substring(i+1, j  ) + // ""
              middle.substring(j  , j+1) + // "s" <--(second letter to be swapped)
              middle.substring(j+1     ) + // "" 
              last                         // "e" 

String word   = "house"; 
String first  = "h"; 
String middle = "ous"; 
String last   = "e";

int i = 2;

int j = 1; 

i = 1; 

j = 2; 

So now we're ready to finish this up. 

Good work Adam, Maxine, Zhichao, JSON and all that helped in class. 

--


  "helicopter"
   0123456789

Let's slice it in 

 (h)(elicopte)(r) 

first  middle  last 

    helicopter 
     0*234*67

    hepicolter
      5   1

 (h)          (r) 

    (elicopte)
     0*234*67

 (e)(l)(ico)(p)(te)
  0  1  234  5  67

 (e)(p)(ico)(l)(te)
  0  5  234  1  67

 (h)          (r) 
     epicolte
      5   1

    hepicolter      

   ------------------(middle)
(s)(dgncy)(i)(weorufhnceria)(j)(oufhxiweufhie)(r)
first
   middle.substring(0, 5) // i is 5 
          middle.substring(5, 5+1) // character at i 
              middle.substring(5+1, 19) // j is 19 
                            middle.substring(j, j+1) // character at j 
                                middle.substring(j+1) // the rest of the middle 
                             // middle.substring(j+1, middle.length()-1) 

So 

sdgncyiweorufhnceriajoufhxiweufhier

(s)(dgncy)(i)(weorufhnceria)(j)(oufhxiweufhie)(r)

becomes 

(s)(dgncy)(j)(weorufhnceria)(i)(oufhxiweufhie)(r)

sdgncyjweorufhnceriaioufhxiweufhier

Let's examine them side by side:

sdgncyiweorufhnceriajoufhxiweufhier
sdgncyjweorufhnceriaioufhxiweufhier

--- end of plan now let's coding

However Austin is asking about a general scramble procedure: 

    scrambled           initial
      ""              "watermelon"           
      "" + "m"        "waterelon"
      "m" + "t"       "waerelon"
In general: 
 scrambled + initial.substring(i, i+1) // where i is random 
                  initial.substring(0, i) + initial.substring(i+1)
      "mt" + "o"      "waereln"
      "mto" + "w"     "aereln"
      ... and so on 
      "mtowlaeenr"    "" and that's where we stop 

And that's it. 

--