Writing Classes Lesson Hacks
My attempt at the Writing Classes Lesson hw
public class WordMatch {
String secret;
public WordMatch(String secret) {
this.secret = secret;
}
public void scoreGuess(String guess) {
int counter = 0;
// for loop for first substring index
for (int i = 0; i < this.secret.length(); i++){
// loop for second substring index
for (int j = i + 1; j < this.secret.length() + 1; j++) {
// if statement
if (guess.equals(this.secret.substring(i,j))) {
counter++;
}
}
}
// Returning a point value
int points = counter * guess.length() * guess.length();
System.out.println("" + guess + " = " + points);
// return points;
}
}
WordMatch game = new WordMatch("mississippi");
game.scoreGuess("i"); game.scoreGuess("iss"); game.scoreGuess("issipp"); game.scoreGuess("mississippi");
WordMatch game = new WordMatch("aaaabb");
game.scoreGuess("a"); game.scoreGuess("aa"); game.scoreGuess("aaa"); game.scoreGuess("aabb"); game.scoreGuess("c");
public class ClubMembers {
private ArrayList<MemberInfo> memberList;
public void addMembers(String[] names, int gradYear) {
for(name : names) {
memberList.add(new MemberInfo(name, gradYear, true));
}
}
}