// APS101, Winter 2009: Lecture 22 (Mar. 5) // // Assignment 2 note: to get full marks for PassportTester.java and SpyTester.java you must test all the methods THOROUGHLY. (i.e. sometimes you should test the method with several different inputs, if it's a more complex method, like addVisited in Passport). // // Review: last time we wrote two new versions of the isPalindrome method, to // improve efficiency. // we also looked at method "mystery" in WhileDemo and practiced tracing the code. // what was difficult about this method? 2 while loops that were NESTED! (one inside the other) // to get some more practice with nested loops, we wrote the method // sentenceWordSplit in NestedLoops.java (take a look at it). // questions regarding tracing code, especially with nested loops, will definitely be on // your final exam, so get as much practice with them as possible. // (see method example1() in ForDemo) // (see method example2() in ForDemo) // A2 clarification: method "stretch" in the Spy class // // let's say we have a key = "1101" // (which is the binary representation of integer 13, but it doesn't matter how we got the key) // then we want to stretch it... // // stretch(key, 2) -> "1101" // there is no change // stretch(key, 4) -> "1101" // also no change, because key is already 4 bits long // stretch(key, 5) // the following happens, according to the algorithm: // half 1 = "11" // half 2 = "01" // XOR the bits // result = "10" // then append the result to the end of the current key // key = key + "10" // key = "110110" // so stretch(key, 5) -> "110110" // how about stretch(key, 8)? repeat the process once more: // half 1 = "110" // half 2 = "110" // result = "000" // key = key + "000" // key = "110110000 // so stretch(key, 8) -> "110110000"