FRQ #1

FRQ Type: Array/ArrayList How key algorithm links to type: This FRQ has three methods, and they all involve using data from an array. The first method iterates through the array to sum the value of each item in the array. The second method

public static int arraySum(int[] array) {
    int sum = 0;
    for (int i=0; i<array.length; i++){
        sum+=array[i];
    }
    return sum;
}

public static int[] rowSums(int[][] arr2D){
    int[] sum = new int[arr2D[0].length];
    for (int i=0; i<arr2D.length; i++) {
        int rowSum = arraySum(arr2D[i]);
        sum[i] = rowSum;
    }
    return sum;
}

public static boolean isDiverse(int[][] arr2D) {
    int[] newArray = rowSums(arr2D);
    boolean diverse = true;
    for (int i=0; i<newArray.length; i++) {
        for (int j=0; j<newArray.length; j++) {
            if(i!=j && newArray[i]==newArray[j]) {
                diverse = false;
            }
        }
    }
    return diverse;
}
public class Test1 {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(arraySum(array));
        int[][] Array1 = {
            {1, 2, 3},
            {4, 5, 6},
            {1, 2, 3}
        };
        int [] rowsums = rowSums(Array1);
        for (int i=0; i<rowsums.length; i++) {
            System.out.print(rowsums[i]+" ");
        }
        System.out.println("");
        System.out.println(isDiverse(Array1));
    }
}
Test1.main(null);
15
6 15 6 
false

FRQ #2

FRQ Type: How key algorithm links to type:

public class HiddenWord {
    private static String word = "";
    HiddenWord(String hidden) {
        word = hidden;
    }

    public static String getHint(String guess) {
        String hint = "";
        for (int i=0; i<word.length(); i++) {
            for (int j=0; j<word.length(); j++) {
                if (i==j && guess.charAt(i)==word.charAt(j)) {
                    hint+=guess.charAt(i);
                    break;
                } else if (i!=j && guess.charAt(i)==word.charAt(j)) {
                    hint+="+";
                    break;
                } else if (j==word.length()-1) {
                    hint+="*";
                }
            }
        }
        return hint;
    }
}
public class Test2 {
    public static void main(String[] args) {
        HiddenWord puzzle = new HiddenWord("HARPS");
        System.out.println(puzzle.getHint("AAAAAA"));
        System.out.println(puzzle.getHint("HELLO"));
        System.out.println(puzzle.getHint("HEARTS"));
        System.out.println(puzzle.getHint("HARMS"));
        System.out.println(puzzle.getHint("HARPS"));
    }
}
Test2.main(null);
+A+++
H****
H*++*
HAR*S
HARPS

This FRQ uses

FRQ #3

FRQ Type: Array/ArrayList How key algorithm links to type: Obviously, this FRQ is based of sparse arrays, so it has to be linked to arrays and ArrayLists. The values of the sparse array are stored in an array list so that thye can be accessed and modified later.

public class SparseArrayEntry {
    private int row;
    private int col;
    private int value;

    public SparseArrayEntry(int r, int c, int v) {
        row = r;
        col = c;
        value = v;
    }

    public int getRow() {
        return row;
    }

    public int getCol() {
        return col;
    }

    public int getValue() {
        return value;
    }
}

public class SparseArray {
    private int numRows;
    private int numCols;
    private List<SparseArrayEntry> entries;

    public SparseArray() {
        entries = new ArrayList<SparseArrayEntry>();
    }

    public void addSparseValue(int r, int c, int v) {
        SparseArrayEntry entry = new SparseArrayEntry(r, c, v);
        entries.add(entry);
    }

    public int getNumRows() {
        int rows = 0;
        for (SparseArrayEntry ent : entries) {
            if (ent.getRow()>rows) {
                rows = ent.getRow();
            }
        }
        numRows=rows;
        return numRows;
    }

    public int getNumCols() {
        int cols = 0;
        for (SparseArrayEntry ent : entries) {
            if (ent.getCol()>cols) {
                cols = ent.getCol();
            }
        }
        numCols=cols;
        return numCols;
    }

    public int getValueAt(int row, int col) {
        for (SparseArrayEntry ent : entries) {
            if (ent.getCol()==col && ent.getRow()==row) {
                return ent.getValue();
            }
        }
        return 0;
    }

    public void removeColumn(int col) {
        List<SparseArrayEntry> temp = new ArrayList<SparseArrayEntry>();
        for (int i=0; i<entries.size(); i++) {
            if (entries.get(i).getCol()==col) {
                continue;
            }
            else {
                temp.add(entries.get(i));
            }
        }
        entries=temp;
    }
}
public class Test3 {
    public static void main(String[] args) {
        SparseArray sparse = new SparseArray();
        System.out.println();
        sparse.addSparseValue(1,4,4);
        sparse.addSparseValue(2,0,1);
        sparse.addSparseValue(3,1,-9);
        sparse.addSparseValue(1,1,5);
        System.out.println(sparse.getValueAt(3,1));
        System.out.println(sparse.getValueAt(2,0));
        sparse.removeColumn(1);
        System.out.println(sparse.getValueAt(3,1));
    }
}
Test3.main(null);
-9
1
0

FRQ #3 involves arrays. There are several different ways that we can use arrays to store information for our project. On the backend, Most of our data will probably be stored in an SQL database, but there are some data that we can store in array. For example, for our quiz game, we can store the quiz questions in an array, and retrieve them when we need to give the user another question. Having the questions in an array will make them easy to access and to get a random item. But on the frontend, we can store information like the user’s score and user information in an array to make it easy to access.

FRQ #4

FRQ Type: Classes How key algorithm links to type: In this FRQ, the NumberGroup class is a parent classes, with two child classes: Range and MultipleGroups. It has one method, the contains method, and since the child classes inherit from the parent class, they also have access to the contains method. In addition, they also have access to the variable, numGroup, since it is defined in the parent class. Other than the constructor, the Range class has no other methods, but the MultipleGroups class overrides the contains method in the parent class.

public class NumberGroup {
    protected List<Integer> numGroup;
    public NumberGroup(List<Integer> group) {
        numGroup = group;
    }

    public boolean contains(int checkNum) {
        for (int num : numGroup) {
            if (checkNum==num) {
                return true;
            }
        }
        return false;
    }
}

public class Range extends NumberGroup {
    public Range(int start, int end) {
        super(new ArrayList<>());
        for (int i=start; i<end+1; i++) {
            numGroup.add(i);
        }
    }
}

public class MultipleGroups extends NumberGroup {
    private List<NumberGroup> groupList;
    public MultipleGroups(List<NumberGroup> groupList) {
        super(new ArrayList<>());
        this.groupList = groupList;
    }

    public boolean contains(int checkNum) {
        for(NumberGroup group : groupList) {
            boolean doesContain = group.contains(checkNum);
            if (doesContain==true) {
                return true;
            }
        }
        return false;
    }
}
public class Test4 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(5);
        list.add(3);
        NumberGroup numgroup = new NumberGroup(list);
        System.out.println(numgroup.contains(2));
        Range range1 = new Range(-3, 2);
        System.out.println(range1.contains(3));
        List<NumberGroup> newList = new ArrayList<>();
        newList.add(new Range(5,8));
        newList.add(new Range(10,12));
        newList.add(new Range(1,6));
        MultipleGroups mult1 = new MultipleGroups(newList);
        System.out.println(mult1.contains(2));
    }
}
Test4.main(null);
false
false
true

This FRQ uses inheritance. Inheritance is a very important part of Java, and we can use it in various different ways in our project. For example, each game in our project has its own leaderboard. We could have a parent scoring class, and then have child classes that inherit the methods from that parent class while adding their own necessary methods. There are some other places that we can use inheritance in our project as well. For example,