CompSci 4Java 3 Nov 28, 2006Prof. Susan RodgerAnnouncements• Assignment 7 – Storyboard due today– Assignment and web page due Thursday• Turn in Alice world, web page, and README file• Also link in web page– Demo due Thursday• Last Java classwork is this Thursday– All classwork must be checked off/submitted by Thursday, Dec. 7 to receive credit.Java – Method/function format• Method must be part of a class• Method must have a return type– Return type is “void” if no return type (method)– DO not use the name of the class or method for any variable• Method has list and type of parameters• Declare types of all local variables first– Exception: loop variablesMore on indexOfString class = “CPS 4 and CPS 6 and CPS 4G”;System.out.println(class.indexOf(“CPS”));System.out.println(class.indexOf(“CPS”, 6));System.out.println(class.indexOf(“CPS”, 14));• IndexOf with a string and number argument finds the position of the first occurrence starting from that number position onProblem• Given a Phrase and a word, return true if the word occurs at least twice in the phrase.Finish Code – What does this do?Java Code - Note• How many variables are there and what are there types?• How many times is a variable declared (given its type)?• Where is the return value?• How many parameters and what are their types?Classwork today• Finish classwork from last time and submit• Classwork today – one APT– Repeated Substrings• Find the longest repeated substring in a phrase that doesn’t overlap• “ABCDABCFG” returns “ABC”• “ABABA” returns “AB” (note ABA appears twice but overlaps, so doesn’t count)• Use indexOf and subString• For every possible substring, see if it occurs
View Full Document