| Sprint 4 & 5 | Girls in CS Panel | 2024 FRQ #2 | Final Exam Review | Final MC and FRQ |
FRQ 2 - Methods - 2024
Homework Assignment for Week 1
Proof of Execution
// Scoreboard FRQ
class Scoreboard {
private String team1;
private String team2;
private int score1;
private int score2;
private boolean team1active;
public Scoreboard(String team1Name, String team2Name) {
team1 = team1Name;
team2 = team2Name;
score1 = 0;
score2 = 0;
team1active = true;
}
public void recordPlay(int points) {
if (points > 0)
{
if (team1active == true)
{
score1 += points;
}
else
{
score2 += points;
}
}
else
{
team1active = !team1active;
}
}
public String getScore() {
if (team1active == true)
{
return score1 + "-" + score2 + "-" + team1;
}
else
{
return score1 + "-" + score2 + "-" + team2;
}
}
}
// Testing the Scoreboard class (DO NOT MODIFY this part unless you change the class, method, or constructer names)
// DO NOT MODIFY BELOW THIS LINE
class Main {
public static void main(String[] args) {
String info;
// Step 1: Create a new Scoreboard for "Red" vs "Blue"
Scoreboard game = new Scoreboard("Red", "Blue");
// Step 2
info = game.getScore(); // "0-0-Red"
System.out.println("(Step 2) info = " + info);
// Step 3
game.recordPlay(1);
// Step 4
info = game.getScore(); // "1-0-Red"
System.out.println("(Step 4) info = " + info);
// Step 5
game.recordPlay(0);
// Step 6
info = game.getScore(); // "1-0-Blue"
System.out.println("(Step 6) info = " + info);
// Step 7 (repeated call to show no change)
info = game.getScore(); // still "1-0-Blue"
System.out.println("(Step 7) info = " + info);
// Step 8
game.recordPlay(3);
// Step 9
info = game.getScore(); // "1-3-Blue"
System.out.println("(Step 9) info = " + info);
// Step 10
game.recordPlay(1);
// Step 11
game.recordPlay(0);
// Step 12
info = game.getScore(); // "1-4-Red"
System.out.println("(Step 12) info = " + info);
// Step 13
game.recordPlay(0);
// Step 14
game.recordPlay(4);
// Step 15
game.recordPlay(0);
// Step 16
info = game.getScore(); // "1-8-Red"
System.out.println("(Step 16) info = " + info);
// Step 17: Create an independent Scoreboard
Scoreboard match = new Scoreboard("Lions", "Tigers");
// Step 18
info = match.getScore(); // "0-0-Lions"
System.out.println("(Step 18) match info = " + info);
// Step 19: Verify the original game is unchanged
info = game.getScore(); // "1-8-Red"
System.out.println("(Step 19) game info = " + info);
}
}
Challenges
Syntax was a big challenge for me. I forgot the brackets multiple times, as well as variable definition. I need to remember to add semicolons after each statement and to memorize the case-sensitivity of Java. Furthermore, I need to remember that “=” assigns values to the variable, while “==” compares values. Finally, when I finish writing my code, I always need to make sure to test it for logical errors, as I accidentally prevented team Red from ever gaining points before reviewing my code.