CompSci 4Java 3 Nov 27, 2007Prof. 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 next Tuesday• Last Java classwork is this Thursday– All Alice classwork must be checked off by 11/30 to receive credit– All Java classwork must be submitted by Dec. 4 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?Adding a helper method to a classpublic class NameOfClass{public String someMethod(String [] str){ // code here}public int helperMethod(String str, int n){ // code here}}Adding a helper class• Note the following– Names of methods and how many– Location of methods– Return types– Parameters– Where do return statements go?Classwork today• Create Java Project: CPS4Sec1Nov27• Classwork today – 3 APTs, 1 is extra credit– Protein Counter – number of strings that have at least 3 copies of given amino acid• Consider a helper function to count number of amino acids in one string– DNAHeavyMax – most frequent occuring nucleotide• Consider a helper function– ProteinFinder – finding a protein• Use indexOf to find codons• Search for stop codon past the start codon, not from beginning of stringExtra Credit• Include extra credit in same project. • Submit all three APTs at the same
View Full Document