CB FRQ
My answers:
Question 1:
a.
public static int hailstoneLength(int n) {
int count = 1;
while (n > 1) {
if (n % 2 == 0) {
n = n / 2;
} else {
n = 3 * n + 1;
}
count++;
}
return count;
}
b.
public static boolean isLongSeq(int n) {
return hailstoneLength(n) > n;
}
C.
public static double propLong(int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
if (isLongSeq(i)) {
count++;
}
}
return (double) count / n;
}
Question 2
public class GameSpinner {
private int sectors;
private int previousSpin = 0;
private int currentLength = 0;
public GameSpinner(int s) {
sectors = s;
}
public int spin() {
int newSpin = (int)(Math.random() * sectors) + 1;
if (newSpin == previousSpin) {
currentLength++;
} else {
previousSpin = newSpin;
currentLength = 1;
}
return newSpin;
}
public int currentRun() {
return currentLength;
}
}
Question 3
a.
public void addReview(ProductReview prodReview) {
reviewList.add(prodReview);
String prodName = prodReview.getName();
boolean found = false;
for (String n : productList) {
if (n.equals(prodName)) {
found = true;
}
}
if (!found) {
productList.add(prodName);
}
}
b.
public int getNumGoodReviews(String prodName) {
int numGoodReviews = 0;
for (ProductReview prodReview : reviewList) {
if (prodName.equals(prodReview.getName())) {
String review = prodReview.getReview();
if (review.indexOf("best") >= 0) {
numGoodReviews++;
}
}
}
return numGoodReviews;
}
Question 4
a.
public Theater(int seatsPerRow, int tier1Rows, int tier2Rows) {
theaterSeats = new Seat[tier1Rows + tier2Rows][seatsPerRow];
for (int r = 0; r < tier1Rows + tier2Rows; r++) {
for (int c = 0; c < seatsPerRow; c++) {
if (r < tier1Rows) {
theaterSeats[r][c] = new Seat(true, 1);
} else {
theaterSeats[r][c] = new Seat(true, 2);
}
}
}
}
b.
public boolean reassignSeat(int fromRow, int fromCol, int toRow, int toCol) {
Seat toS = theaterSeats[toRow][toCol];
if (!toS.isAvailable()) {
return false;
}
Seat fromS = theaterSeats[fromRow][fromCol];
if (toS.getTier() < fromS.getTier()) {
return false;
}
toS.setAvailability(false);
fromS.setAvailability(true);
return true;
}
Grade:
Total Score: 31/36 Grade: 85% β B+ Comment: Strong coder alert π¨ Just a few little slips between you and perfection.
π§ Question 1: Hailstone Sequence
a: β Perfect logic, structure, and iteration.
b: β Accurate boolean return.
c: β οΈ Tiny stylistic nitpick: You could cache hailstoneLength(i) in a variable to avoid double computation if expanded. Not a real error, just a performance consideration.
Score: 8/9 Comment: Logic checks out. Maybe consider edge cases like n = 0 even though not required by College Board.
π Question 2: GameSpinner
β Fields set up right.
β Good use of Math.random().
β οΈ Minor style suggestion: Reset previousSpin in constructor to make behavior more explicit and avoid hidden state if reused in testing.
Score: 8/9 Comment: Works well, just lacks some initial clarity in constructor setup.
ποΈ Question 3: Product Reviews
a: β Logic works. β οΈ Slight deduction: Could add a break; once found is set to true β not wrong, just a chance to optimize.
b: β Correct use of .indexOf, checks product name well.
Score: 7/9 Comment: The loop can be a little cleaner in addReview. Great understanding of objects and string matching though.
π Question 4: Theater Seating a: β Nailed the initialization logic.
b: β Tier check and availability logic are perfect.
No deductions here.
Score: 8/9 Comment: Solid job! Logic is clean, very readable. Bonus points for clean formatting.