Pitsco / personal

MIT License
0 stars 0 forks source link

CB and PBL Connection #6

Open Pitsco opened 4 months ago

Pitsco commented 4 months ago

Question 1, Arraylist (Arrays/2D Arrays):

This question primarily focused on arraylists with a side addition of 1D arrays and 2D arrays. Knowing how to iterate through each array was key for this question because we needed to know how to add each value to find the sum of the rows of the 1D or 2D array.

package com.nighthawk.spring_portfolio.mvc.Statistics;

// other imports...

import java.util.ArrayList;

private List<JSONObject> playersData;

// pulling and parsing data is not shown...

this.playersData = new ArrayList<>(playerDataArray);

The code above is a sample usage of arraylists in our code from a file called PlayerGeneralController.java which generates all players ever in the NBA and their basic stats (name, height, most current team, etc.).

The player data is stored in a List named playersData. This list is created using the ArrayList implementation, but the type of the variable is the more general List:

private List<JSONObject> playersData;

Later in the code, player data is fetched from the API, and the playersData list is instantiated as an ArrayList:

this.playersData = new ArrayList<>(playerDataArray);

In this line, playerDataArray (which is a JSONArray) is converted to an ArrayList and assigned to the playersData variable.

The code uses the List interface and the ArrayList implementation, but the specific variable type is List. This connects back to them problem in question 1 because I also instantiated a list based on the sum of the rows:

int[] sums = new int[numRows];

Instead of creating a arraylist of player data, I created a new list of the sums of each row.

More about the progress with the code above:

This file was left unfinished by me. I archived it because it wasn't as important as an individual stats page. I would like to possibly touch on in third trimester for all 2023-2024 players instead of ALL NBA players because looking at ALL players would be pointless for a fantasy draft (that regards to the most current season).

Question 2, Classes:

This question focused mainly on classes, constructors, instance variables, and methods. Understanding how to write and set them is crucial to any type of java code as Java is consisted of those 4 factors.

package com.nighthawk.spring_portfolio.mvc.Statistics;

// imports...

public class PlayerSearchName { //class

    private final String API_URL = "https://www.balldontlie.io/api/v1/players"; //setting instance variable

    public String getPlayersByName(@RequestParam String search) { //method
        // Construct the API URL with the search parameter
        String apiUrlWithSearch = API_URL + "?search=" + search;

        // Use RestTemplate to make a GET request to the API 
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForObject(apiUrlWithSearch, String.class);

        return result;
    }
}

The code above is found in our PlayerSearchName.java file, which is solely used to find a player's name based off their name. It has the class name of PlayerSearchName (respective to the java file's name) with an instance variable of API_URL that is set as a string. The method is getPlayerByName is used to make a REST template that can pull the individual data into a String type. Although it is not as simplistic as the problem from College Board's 2015 problem 2, it definitely shows the required understanding of the linkage between classes, constructors, methods, and instance variables.

More about the progress with the code above:

Originally, I would always search by player id in PlayerSpecificController.java through:

String apiUrl = "https://www.balldontlie.io/api/v1/players/" + id;

But searching by id instead of name is way more difficult for the user. I've fixed that with PlayerSearchName.java using:

String apiUrlWithSearch = API_URL + "?search=" + search;

Although this seems very minor, I think finally being able to understand what type of data that was pulled from the api (arrays) and how to search that data based on different functions has been a big improvement for me. In AP CSP, I didn't understand what pulling API data even meant. Now that I'm in CSA, pulling API data through backend has been easier to do than ever.

Question 3, 2D Arrays:

2D Arrays are very useful when storing data proficiently. In our code, however, we don't have much 2D arrays scattered around. Majority of our data stored is through arrays or lists.

If I were to create a 2D array to store the stats, I could create a 2D array to store player stats where each row represents a player, and each column represents a specific stat. Let's assume you have player stats like points, rebounds, assists, and so on. Here's an example of how you might create a 2D array for this purpose"

public class PlayerStatsExample {
    public static void main(String[] args) {
        // Assuming you have an array of player names
        String[] playerNames = {"Player1", "Player2", "Player3"};

        // Create a 2D array for player stats
        int[][] playerStats = new int[playerNames.length][4];  // Assuming 4 stats (adjust as needed)

        // Populate the 2D array with some example data
        playerStats[0][0] = 20;  // Player1's points
        playerStats[0][1] = 8;   // Player1's rebounds
        playerStats[0][2] = 5;   // Player1's assists
        playerStats[0][3] = 2;   // Player1's steals

        playerStats[1][0] = 15;  // Player2's points
        playerStats[1][1] = 12;  // Player2's rebounds
        playerStats[1][2] = 3;   // Player2's assists
        playerStats[1][3] = 1;   // Player2's steals

        playerStats[2][0] = 25;  // Player3's points
        playerStats[2][1] = 6;   // Player3's rebounds
        playerStats[2][2] = 8;   // Player3's assists
        playerStats[2][3] = 3;   // Player3's steals

        // Display player stats
        for (int i = 0; i < playerNames.length; i++) {
            System.out.println(playerNames[i] + " stats:");
            System.out.println("Points: " + playerStats[i][0]);
            System.out.println("Rebounds: " + playerStats[i][1]);
            System.out.println("Assists: " + playerStats[i][2]);
            System.out.println("Steals: " + playerStats[i][3]);
            System.out.println();
        }
    }
}

So, if you have an array of player names (Player1, Player2, Player3), you can create a 2D array where the element at position [i][j] represents the stat j for player i. This way, you can organize and store the player stats in a structured manner, making it easy to retrieve and manipulate individual player stats.

It comes back to the CB 2015 Problem 3 because the two classes, SparseArrayEntry and SparseArray, are for representing and efficiently manipulating sparse arrays. A sparse array is a two-dimensional array where most elements are zero, and non-zero values are stored along with their row and column indices. The SparseArray class includes methods to get the value at a specific position (getValueAt) and to remove a column efficiently (removeColumn).

Question 4, Method and Control Structures:

Although interfaces are not used anymore in the exam, learning it is still better than not learning it. I remember a question that was with interface in the CB 2014 MC. img

It had a similar format as the interface both served a relatively same purpose. However, instead of defining the getMileage() method as a double, this CB 2015 FRQ wanted us to return a Boolean value if this interface was implemented into a class.

package com.nighthawk.spring_portfolio.mvc.person;

import org.springframework.data.jpa.repository.JpaRepository;

public interface  PersonRoleJpaRepository extends JpaRepository<PersonRole, Long> {
    PersonRole findByName(String name);
}

The PersonJpaRepository interface demonstrates the practice of Spring Data JPA for handling database operations. Extending the basic JpaRepository provides handy CRUD functionalities, making data management more straightforward. The interface offers flexibility through custom queries using the @Query annotation, allowing for more complex database interactions.

This is similar to CB 2015 Problem 4, with the NumberGroup interface and its implementation in the MultipleGroups class. It provides a straightforward way to manage groups of numbers. MultipleGroups efficiently handles a list of NumberGroup instances, simplifying the process of checking for the presence of numbers within these groups.

Mr. Mort's Reference

Overall Reflection:

h4seeb-cmd commented 4 months ago

Crossover Grading

FRQ Blogs | 3.72/3.6

Overall, these blogs were done well. You provide lots of context to the question, pretty much porting over the CollegeBoard question, explanations and all. The runtime code was there and functioning as well, outputs being nicely organized.

FRQ Grade Explanation
1 0.92/0.9 Code functions as required, reflections are thoughtful and sufficiently in depth. Something I really appreciated was how you integrated code cells into your reflection.
2 0.97/0.9 Code functions as required, reflections were not as in depth, but they were sufficient. Explaining choice of StringBuilder was very good. and the user input with scanner was very clever and well implemented. Extra functionality was a nice touch. I learned what StringBuilder is and how I can use it to analyze strings for various purposes. I will definitely be using this in the future.
3 0.91/0.9 Everything was done as required. Code was functional, and reflections were pretty good. Not much to say here.
4 0.92/0.9 Code was functional, and reflection was good. I liked how you provided an example of how an interface would be implemented.

Implementation Issue | 3.65/3.6

This issue was pretty well constructed. Sufficient evidence of implementation to project concept given. Explanations helped me connect the dots between FRQ concepts and project implementation. Reflections were ok as well, nothing super deep/insightful, but it serves as a good reflection on work and ability. Things you could've improved on include:

Total: 7.37/7.2