Howdy.

Next week: continue the reading assignments

The topics would be:

  (a) the class extension mechanisms, inheritance, polymorphism, dynamic 
      method lookup, constructor chaining, shadowing of variables, patterns

  (b) start modeling your BSTs

There is an exam tomorrow. 


                 60 marbles 
Adrian  Michael
           2     58 
20               38
          10     28
13               15 <-------- Adrian on the winning path 
           7      8
 1                7 
           3      4
 1                3
           1      2
 1                1
           1 and you lose   

Write a program so you can play against the computer. 

import java.util.Scanner;

public class Example {
  public static void main(String[] args) {
    String sentence = // "There and waterfall is a pineapple what surprising excellent intimidating."; 
      "Snoop Dogg Clothing, that's what I'm groomed in."; 
    Scanner read = new Scanner(sentence); 
    String result = "";
    while (read.hasNext()) {
      String token = read.next(); 
      token = swap(token); 
      result = token + " " + result; 
    }
    System.out.println( result ); 
  }
  public static String swap(String word) {
    if (word.length() <= 1) return word;  
    String first = word.substring(0, 1), 
           last = word.substring(word.length()-1), 
           middle = word.substring(1, word.length()-1); 
    
    return last + middle + first; 
  }
}

--

Emma reminded me to remind you that magic squares built by our 
program(s, as shown in class yesterday) only have size an odd number. 

--

import java.util.Scanner;

public class Whatever {
  public static void main(String[] args) {
    { 
      int i = 2, j = 3; 
      System.out.println( i + j ); 
    }
    {
      char i = 'a', j = 'b';
      System.out.println( i + j ); 
    }
    { 
      int i = 2, j = 3; 
      System.out.println( i + j ); 
    }
  }
}

--