Question 1a

  • Write a static method arraySum that calculates and returns the sum of the entries in a specified one-dimensional array. The following example shows an array arr1 and the value returned by a call to arraySum.
public class FantasyFootball {
    public static void main(String[] args) {

        int[] fantasyPoints = {23, 14, 30, 10}; 

        int totalPoints = arraySum(fantasyPoints);

        System.out.println("Projected fantasy points for your NFL team this week: " + totalPoints);
    }

    public static int arraySum(int[] arr) {
        int sum = 0;
        for (int points : arr) {
            sum += points;
        }
        return sum;
    }
}

FantasyFootball.main(null); 

Total compounds tested this week: 77

1b

public class ResearchResourceAllocation {
    public static void main(String[] args) {
        int[][] researchPhases = {
            {1, 3, 2, 7, 3},
            {10, 10, 1, 6, 6},
            {5, 3, 5, 9, 6},
            {7, 6, 4, 2, 1}
        };
        int[] resourcesPerPhase = rowSums(researchPhases);
        for (int i = 0; i < resourcesPerPhase.length; i++) {
            System.out.println("Phase " + (i + 1) + " total resources: " + resourcesPerPhase[i]);
        }
    }

    public static int arraySum(int[] arr) {
        int sum = 0;
        for (int num : arr) {
            sum += num;
        }
        return sum;
    }

    public static int[] rowSums(int[][] arr2D) {
        int[] sums = new int[arr2D.length];
        for (int i = 0; i < arr2D.length; i++) {
            sums[i] = arraySum(arr2D[i]); 
        }
        return sums;
    }
}
ResearchResourceAllocation.main(null);

Phase 1 total resources: 16
Phase 2 total resources: 33
Phase 3 total resources: 28
Phase 4 total resources: 20

1c

public class JungleExpedition {
    
    public static void main(String[] args) {
        // 2D array where each row represents a different research group's findings
        int[][] researchFindings = {
            {1, 3, 2, 7, 3},
            {10, 10, 1, 6, 6},
            {5, 3, 5, 9, 6},
            {7, 6, 4, 2, 1}
        };

        System.out.println("Do all research groups have unique findings? " + isDiverse(researchFindings));
    }
    public static int arraySum(int[] arr) {
        int sum = 0;
        for (int num : arr) {
            sum += num;
        }
        return sum;
    }

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

    public static boolean isDiverse(int[][] arr2D){
        int [] sums = rowSums(arr2D);
        for (int i = 0; i < sums.length; i++){
            for (int j = i + 1; j < sums.length; j++){
                if (sums[i] == sums[j]){
                    return false;
                }
            }
        }
        return true;
    }
}

JungleExpedition.main(null);

Do all research groups have unique findings? true

This FRQ from the AP Computer Science A exam was mainly focused on static methods to do one-dimensional and two-dimensional arrays. The FRQ required implementing algorithms to sum elements within arrays and compare those sums to assess diversity. Loop constructs were essential for traversing array elements. By completing the earlier parts, I could construct a final method that determined the uniqueness of row sums in a 2D array, symbolizing a critical step in data analysis similar to verifying the differences of research results in a scientific study.

I used this frq and related the code by creating the theme to our first trimester final project of cancer research.