public class Hailstone {
    public static int hailstoneLength(int n) {
        int ct = 1;

        while (n != 1) {
            if (n % 2 == 0) {
                n /= 2;
            } else {
                n = 3 * n + 1;
            }
            ct++;
        }
        return ct;
    }

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

    public static double propLong(int n) {
        int longSeqs = 0;

        for (int i = 1; i <= n; i++) {
            if (isLongSeq(i)) {
                longSeqs++;
            }
        }

        return (double)longSeqs / n;
    }

    public static void main(String[] args) {
        System.out.println(hailstoneLength(5));
        System.out.println(hailstoneLength(8));

        System.out.println(isLongSeq(5));
        System.out.println(isLongSeq(8));

        System.out.println(propLong(10));
    }
}

import java.util.Random;

public class GameSpinner {
    int c = 0;
    int n;
    int currentSpin = 0;

    Random rand = new Random();

    public GameSpinner(int n) {
        this.n = n;
    }

    public int currentRun() {
        return c;
    }

    public int spin() {
        int spin = rand.nextInt(n) + 1;
        if (spin == currentSpin) {
            c++;
        } else {
            c = 1;
            currentSpin = spin;
        }

        return spin;
    }

    public static void main(String[] args) {
        GameSpinner g = new GameSpinner(4);
        for (int i = 0; i < 5; i++) {
            System.out.println(g.currentRun());
            System.out.println(g.spin());
        }

    }
}

public class ProductReview {
    private String name;
    private String review;

    public ProductReview(String pName, String pReview) {
        name = pName;
        review = pReview;
    }

    public String getName() {
        return name;
    }

    public String getReview() {
        return review;
    }
}

import java.util.ArrayList;

public class ReviewCollector {
    private ArrayList<ProductReview> reviewList;
    private ArrayList<String> productList;

    public ReviewCollector() {
        reviewList = new ArrayList<>();
        productList = new ArrayList<>();
    }

    public void addReview(ProductReview prodReview) {
        reviewList.add(prodReview);
    }

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

        for (ProductReview product : reviewList) {
            if (product.getName().equals(prodName) && product.getReview().contains("best")) {
                c++;
            }
        }

        return c;
    }
}

public class Seat {
    private boolean available;
    private int tier;

    public Seat(boolean isAvail, int tierNum) {
        available = isAvail;
        tier = tierNum;
    }

    public boolean isAvailable() {
        return available;
    }

    public int getTier() {
        return tier;
    }

    public void setAvailablity(boolean isAvail) {
        available = isAvail;
    }
}

public class Theater {
    private Seat[][] theaterSeats;
    int row = 0;

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

        for (int i = 0; i < tier1Rows; i++) {
            for (Seat seat : theaterSeats[row]) {
                seat = new Seat(true, 1);
            }
            row++;
        }

        for (int i = 0; i < tier2Rows; i++) {
            for (Seat seat : theaterSeats[row]) {
                seat = new Seat(true, 2);
            }
            row++;
        }
    }

    public boolean reassignSeat(int fromRow, int fromCol, int toRow, int toCol) {
        if (!theaterSeats[fromRow][fromCol].isAvailable() || theaterSeats[toRow][toCol].isAvailable()) {
            return false;
        }

        theaterSeats[fromRow][fromCol] = new Seat(true, theaterSeats[fromRow][fromCol].getTier());
        theaterSeats[toRow][toCol] = new Seat(false, theaterSeats[toRow][toCol].getTier());
        return true;
    }
}