Unit 5: Writing Classes
// modifier, return type, name, parameters
public double getArea (double width, double height) {
// method body
}
// 1a: write the method scoreGuess
public class WordMatch {
private String secret;
public WordMatch(String word) {
}
public int scoreGuess(String guess) {
int score = 0;
for (int i = 0; i<= secret.length()-guess.length(); i++) {
if (secret.substring(i, i+guess.length()) == guess) {
score++;
}
}
}
return score * guess.length() * guess.length();
}
// 3a: Write the ClubMembers method addMembers
public class ClubMembers {
private ArrayList<MemberInfo> memberList;
public void addMembers(String[] names, int gradYear) {
for (String name : names) {
memberList.add(new MemberInfo(name, gradYear, t));
}
}
}