Methods and Control Structure FRQ

public class GetCheck {
    public static int getCheck(int num){
        int sum = 0;
        int len = getNumberOfDigits(num);
        for (int i = 1; i <= len; i++){
                sum += getDigit(num, i) * (8 - i);
        }
        return sum % 10;
    }


    public static int getNumberOfDigits(int num){
        int count = 0;
        while(num > 0){
            num /= 10;
            count++;
        }
        return count;
    }

    
    public static int getDigit(int num, int n){
        int digit = 0;
        int len = getNumberOfDigits(num);
        for (int i = 0; i < len - n + 1; i++){
            digit = num % 10;
            num /= 10;
        }
        return digit;
    }

    public static boolean isValid(int numWithCheckDigit){
        return getCheck(numWithCheckDigit/10) == numWithCheckDigit % 10;
    }
    

    public static void main(String[] args){
        System.out.println("Number of digits in 1234: " + GetCheck.getNumberOfDigits(1234));
        System.out.println("3rd Digit of 1234: " + GetCheck.getDigit(1234, 3));
        System.out.println("Check Value of 28415: " + GetCheck.getCheck(283415));
        System.out.println("Checking if 1592 is valid: " + GetCheck.isValid(1592));
        System.out.println("Checking if 1593 is valid: " + GetCheck.isValid(1593));
    }
}

GetCheck.main(null);
Number of digits in 1234: 4
3rd Digit of 1234: 3
Check Value of 28415: 6
Checking if 1592 is valid: true
Checking if 1593 is valid: false

Classes frq

public class AdditionalPattern { 
    private int start;
    private int current;
    private int increment;

    public AdditionalPattern(int start, int increment){
        this.start = start;
        this.increment = increment;
        this.current = start;
    }

    public int currentNumber() {
        return current;
    }

    public void next() { 
        current += increment;
    }

    public void prev() { 
        current -= increment;
    }

    public static void main(String[] args){
        AdditionalPattern plus3 = new AdditionalPattern(2, 3);

        System.out.println(plus3.currentNumber());
        plus3.next();
        System.out.println(plus3.currentNumber());
        plus3.prev();
        System.out.println(plus3.currentNumber());
    }
}
AdditionalPattern.main(null);
2
5
2

Arrays & ArrayList FRQ

public class MemberInfo { 
    private String name;
    private int gradYear;
    private boolean hasGoodStanding;

    public MemberInfo(String name, int gradYear, boolean hasGoodStanding){
        this.name = name;
        this.gradYear = gradYear;
        this.hasGoodStanding = hasGoodStanding;
    }

    public int getGradYear() {
        return gradYear;
    }

    public boolean inGoodStanding() {
        return hasGoodStanding;
    }

    public String toString(){
        return (name + " " + gradYear + " " + hasGoodStanding);
    }
}

public class ClubMembers { 
    private static ArrayList<MemberInfo> memberList = new ArrayList<MemberInfo>();

    public static void addMembers(String[] names, int gradYear){
        for(String name: names){
            memberList.add(new MemberInfo(name, gradYear, true));
        }
    }

    public static ArrayList<MemberInfo> removeMembers(int year){
        ArrayList<MemberInfo> goodStanding = new ArrayList<MemberInfo>();

        int i = 0;
        while(i < memberList.size()){
            if(memberList.get(i).getGradYear() <= year){
                MemberInfo removedMember = memberList.get(i);
                memberList.remove(i);
                if(removedMember.inGoodStanding()){
                    goodStanding.add(removedMember);
                }
            }
            else i++;
        }
        return goodStanding;
    }

    public static void main(String[] args){
        String[] names1 = new String[]{"John", "Jeff", "Joseph"};
        String[] names2 = new String[]{"Galileo", "Newton", "Isaac", "Archimedes"};

        ClubMembers.addMembers(names1, 2019);
        ClubMembers.addMembers(names2, 2015);

        System.out.println("Members list: ");
        System.out.println(ClubMembers.memberList);
        System.out.println("");
        System.out.println("Good Standing Graduates: ");
        System.out.println(ClubMembers.removeMembers(2015));
        System.out.println("");
        System.out.println("Current Members after 2015: ");
        System.out.println(ClubMembers.memberList);
    }

}
ClubMembers.main(null);
Members list: 
[John 2019 true, Jeff 2019 true, Joseph 2019 true, Galileo 2015 true, Newton 2015 true, Isaac 2015 true, Archimedes 2015 true]

Good Standing Graduates: 
[Galileo 2015 true, Newton 2015 true, Isaac 2015 true, Archimedes 2015 true]

Current Members after 2015: 
[John 2019 true, Jeff 2019 true, Joseph 2019 true]

2D Array FRQ

public class ArrayResizer {
    public static boolean isNonZeroRow(int[][] array2D, int r){
        for(int val: array2D[r]){
            if(val == 0){
                return false;
            }
        }
        return true;
    }

    public static int numNonZeroRows(int[][] array2D) { 
        int count = 0;
        for(int r = 0; r < array2D.length; r++){
            if(isNonZeroRow(array2D, r)){
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args){
        int[][] arr =  {{2, 1, 0},
                    {1, 3, 2},
                    {0, 0, 0},
                    {4, 5, 6}};
        
        System.out.println("Is row 0 non-zero? " + isNonZeroRow(arr, 0));
        System.out.println("Is row 1 non-zero? " + isNonZeroRow(arr, 1));
        System.out.println("Number of non-zero rows: " + numNonZeroRows(arr));
    }
}
ArrayResizer.main(null);
Is row 0 non-zero? false
Is row 1 non-zero? true
Number of non-zero rows: 2

Random Practice - 2014 #3

public class Student {
    private String name;
    private int absenceCount; 

    public String getName(){
        return name;
    }

    public int getAbsenceCount(){
        return absenceCount;
    }
}

public class SeatingChart {
    private Student[][] seats;

    public SeatingChart(List<Student> studentList, int rows, int cols){
        seats = new Student[rows][cols];
        int i = 0;
        for(int c = 0; c < cols; c++){
            for(int r = 0; r < rows; r++){
                seats[r][c] = studentList.get(i);
                i++;
            }
        }
    }

    public void removeAbsentStudents()
}