Lesson hacks for classes
FRQ Hacks from the presentaiton
// 2021 FRQ 1a
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");
// 2021 FRQ 3a
public class ClubMembers {
private ArrayList<MemberInfo> memberList;
public void addMembers(String[] names, int gradYear) {
for(String name : names) {
memberList.add(new MemberInfo(name, gradYear, true));
}
}
}
// NOTE: This can't be run without having the other class and methods
Vocab in this unit
-
Enhanced For Loop - A for loop that iterates through something and automatically gives the value of the element withing its loop without having to use the index. Used in the syntax
for (type var : array)
. -
Standard for loop - A for loop that iterates through something and gives the index of the element within its loop. Used in the syntax
for (int i = 0; i < array.length; i++)
.