Question 1

A

public static int hailstoneLength(int n) {
    int count = 1;
    while (n !== 1) {
        if (n%2 ==0 ) {
            n=n/2;}
        else {
            n=3n+1;}
            count++;
        }
        return count;
}

B

public static boolean isLongSeq(int n) {
    return hailstoneLength(n) > n;
}

C

public static double propLong(int n) {
    int total = 0;
    for ( i=1; i<=n; i++){
        if (isLongSeq(i)) {
            total++;}
        }
        return (double) total/n;
    }

Question 2

public class GameSpinner {
    public int sector;
    public int lastSpin;
    public int run;
    public GameSpinner(int n) {
        sector = n;
        lastSpin = 0;
        run =0;
    }
        public static int spin {
            int newSpin = (int)(Math.random() * sector +1);
            if (newSpin == lastSpin) {
                run++;
            }
            else {
                run =1;
                lastSpin = newSpin;
            }
            return newSpin;
        }
        public int currentRun() {
            return run;
        }
    }

Question 3

A

public void addReview(ProductReview prodReview) {
    reviewList.add(prodReview);
    String newProdName = prodReview.getName();
    for (int i = 0; i < productList.size; i ++) {
        if (!newProdName.equals(productList.get(i))) {
            productList.add(newProdName);
            }
        }
    }

B

public int getNumGoodReviews(String prodName) {
    int nBestReview = 0;

    for (int i = 0; i < reviewList.size(); i++) {
        if (prodName.equals(reviewList.get(i).getName())) {
            if (reviewList.get(i).getReview().indexOf("best")!=-1) {
                nBestReview++;
            }
        }

    }
    return nBestReview;
}

Question 4

A

public Theater (int seatsPerRow, int tier1Rows, int tier2Rows) {
    Seat[][] theaterSeats = new Seat[tier1Rows + tier2Rows][seatsPerRow];

    for (int r = 0; r < theaterSeats.length; r++) {
        for (int c = 0l 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) {
    if (!theaterSeats[toRow][toCol].isAvailable() || theaterSeats[toRow][toCol].getTier < theaterSeats[fromRow][fromCol]) {
        return false;
    }
    theaterSeats[toRow][toCol].setAvailability(false);
    theaterSeats[fromRow][fromCol].setAvailability(true);
    return true;
}