akshat122805 / akshatCSA

CSA First Blog
MIT License
0 stars 1 forks source link

Associations of FRQs & place.com #14

Open akshat122805 opened 8 months ago

akshat122805 commented 8 months ago

Problem 1: Arrays/Arraylists

The arraylists FRQ focused on me creating a program that sums elements that determines the value of each poker hand. This problem involved tackling a series of challenges related to arrays, particularly focusing on summing elements and analyzing the uniqueness of sums in a two-dimensional array context. The principles that I used to solve this problem all hinged on working with arrays, which are ubiquitous in our team's project. Here is an example:

@ManyToMany(fetch = EAGER)
private Collection<PersonRole> roles = new ArrayList<>();

This line of code is part of the Person class and it sets up a way to keep track of different roles a person can have, using an ArrayList. The @ManyToMany annotation indicates that each Person can have many roles, and each PersonRole can be associated with many Person objects. The fetch = EAGER part means that whenever a Person object is retrieved from the database, all its associated PersonRole objects are also loaded immediately into memory. The roles variable is initialized as a new ArrayList, which is a type of collection that allows for dynamic arrays that can grow as needed. This setup is crucial for managing user permissions and roles within an application, allowing for a flexible and dynamic assignment of roles to different users.

Problem 2: Classes

I had to make a HiddenWord class, which I disguised it as PokerHand in order for the user to guess which poker hand they were being dealt when being randomly assigned five cards. This task was about putting together information and actions in one neat class setup. Making a good class was really important for our team's project to work well. Here's an example:

@Entity
public class Channel {

    @Id @GeneratedValue
    @Column(name = "channel_id")
    private Long Id;
    private String name;
    private String desc;
    private String creator;

    public Long getId() {
        return Id;
    }

    public void setId(Long id) {
        Id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getCreator() { 
        return creator; 
    }

    public void setCreator(String creator) { 
        this.creator = creator; 
    }

The Channel class in this block of code is an example of a POJO, which can be designed for use in a project like ours (PLACE.com, a Discord replica). It encapsulates properties such as a channel's ID, name, description, and creator, along with corresponding getter and setter methods for manipulating these properties. POJOs were also used in our Messages.java file which took into account of the user, time stamp, and channel ID. This class structure is similar to what's required in the FRQ question for creating a HiddenWord class, where you define properties and methods (like getHint) specific to the functionality of a guessing game. Both scenarios utilize the principles of object-oriented programming to manage data and behavior, highlighting how POJOs can be great to fit the needs of different applications, from managing communication channels to implementing game logic. By doing this, everything is starting to click and I'm really understanding why POJOs are so applicable and useful.

Problem 3: 2D Arrays

FRQ 3 asked about 2D arrays and sparse arrays. The FRQ's context a some google searches helped me learn that sparse arrays are used to basically manipulate stored data in any given array.

In PLACE, we didn't have 2D arrays or sparse arrays, as we had barbaric ways of storing data :), since we don't have any utilization of 2D arrays, I figured I could talk about how we could use 2D arrays (The Veracious V's suggested I do this, and we could definitely do this for PLACE).

We could use 2D arrays to manage a grid-like structure of messages or information. Imagine a bulletin board or a dashboard where each cell in the 2D array represents a specific slot that can hold a message or a piece of data. This setup could be particularly useful for organizing messages by categories or priorities, with one dimension of the array representing different categories like announcements, reminders, alerts, and the other dimension representing priority levels or time slots. Users could navigate through this arrangement to post new messages, update existing ones, or retrieve information based on its categorization and importance. Using 2D arrays and sparse arrays not only makes the data management better but also takes advantage of the spatial organization for quick access and updates, making user experience with PLACE far better.

Learning about this, I talked to Orlando, Shreyas, Shivansh, and Mati, and we all came to a consenseus that we should approach this for the next trimester portion of our project. Its cool and funny to see how an FRQ from collegeboard completely questioned and humbled the approach of our project's backend infrastructure.

Since I was curious, I decided to ask ChatGPT how we would implement 2D arrays and sparse arrays, it came up with this, along with an example:

public class BulletinBoard {
    private final String[][] board; 
    private final int categories = 3; 
    private final int priorities = 3; 

    public BulletinBoard() {
        this.board = new String[categories][priorities]; 
    }

    // Method to post a message
    public void postMessage(int category, int priority, String message) {
        if (category < categories && priority < priorities) {
            board[category][priority] = message;
        } else {
            System.out.println("Invalid category or priority");
        }
    }

    // Method to get a message
    public String getMessage(int category, int priority) {
        if (category < categories && priority < priorities) {
            return board[category][priority];
        } else {
            return "Invalid category or priority";
        }
    }

    // Method to display the bulletin board
    public void displayBoard() {
        for (int i = 0; i < categories; i++) {
            for (int j = 0; j < priorities; j++) {
                System.out.println("Category: " + i + ", Priority: " + j + ", Message: " + board[i][j]);
            }
        }
    }
}

AND here is the example provided:

public class Main {
    public static void main(String[] args) {
        BulletinBoard bulletinBoard = new BulletinBoard();

        // Posting messages
        bulletinBoard.postMessage(0, 0, "Meeting at 10 AM"); 
        bulletinBoard.postMessage(1, 1, "Submit reports by Friday"); 
        bulletinBoard.postMessage(2, 2, "System maintenance this weekend"); 

        // Displaying the bulletin board
        bulletinBoard.displayBoard();

        // Retrieving a specific message
        String message = bulletinBoard.getMessage(0, 0);
        System.out.println("Retrieved Message: " + message);
    }
}

Problem 4: Methods and Control Structures

This question was mainly about using interfaces, especially how to work with methods and rules for organizing code. Even though interfaces aren't a separate question type on the AP test anymore, they're still important here. We had to make an interface called NumberGroup for a set of numbers and write a method to check if a number is part of the set (using true and false, a lot of students did this as a solution). In part b, for the Range class, we implemented this check method and used if statements to see if a number falls within a certain range. Then, in the MultipleGroups class, we used loops to go through different NumberGroups to find if a number is in any of them. So, this whole question was about using interfaces, making classes, writing methods, and using if statements and loops in Java.

Here is an examples of methods and control structures being used in our team project:

package com.nighthawk.spring_portfolio.mvc.person;

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

import java.util.List;

/*
Extends the JpaRepository interface from Spring Data JPA.
-- Java Persistent API (JPA) - Hibernate: map, store, update and retrieve database
-- JpaRepository defines standard CRUD methods
-- Via JPA the developer can retrieve database from relational databases to Java objects and vice versa.
 */
public interface PersonJpaRepository extends JpaRepository<Person, Long> {
    Person findByEmail(String email);

    List<Person> findAllByOrderByNameAsc();

    // JPA query, findBy does JPA magic with "Name", "Containing", "Or", "Email", "IgnoreCase"
    List<Person> findByNameContainingIgnoreCaseOrEmailContainingIgnoreCase(String name, String email);

    /* Custom JPA query articles, there are articles that show custom SQL as well
       https://springframework.guru/spring-data-jpa-query/
       https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods
    */
    Person findByEmailAndPassword(String email, String password);

    // Custom JPA query
    @Query(
            value = "SELECT * FROM Person p WHERE p.name LIKE ?1 or p.email LIKE ?1",
            nativeQuery = true)
    List<Person> findByLikeTermNative(String term);
    /*
      https://www.baeldung.com/spring-data-jpa-query
    */
}

This code snippet is for a PersonJpaRepository in our project PLACE, a user to channel platform, and it's a part of how the application talks to the database to manage user information. It uses Spring Data JPA, a tool that helps easily access and manipulate database content without needing to write complex SQL queries. For example, it can find a person by their email, sort all people by name, or search for people by name or email regardless of case sensitivity. This is similar to the FRQ question about writing a method or control structure because both involve creating specific instructions to perform tasks—like retrieving or organizing data in this repository, or generating hints based on guesses in the FRQ's guessing game. Essentially, it's about writing code that tells the computer how to accomplish a particular job, whether that's managing user data in PLACE.com or solving a problem in the FRQ.

Reflecting on the FRQs and Tri 2 Part of our Project.

By doing these four FRQs and realizing how the code are group had built for our project was related, made me understand why we studied certain concepts in class and had student lessons on them. It also made me realize which parts of computing theory I lacked understanding and needed more practice in.

The FRQ on classes was better than the rest of the FRQs for me, since our student lesson was on the introduction on POJOs and how they should be formatted. When working with Orlando on the channel creation aspect of our project, we incorporated many POJOs for things like username, channelID, description, etc. When doing this FRQ about my concept of poker, I recalled how we used POJOs not only in Channels.java but also in other parts of our project like Messages.java. This made it easier for me to understand classes, helping me complete the FRQ.

The FRQs on 2D arrays and methods/control structures/interfaces were on the harder side. The main problem was that our project never utilized SparseArrays/2D arrays, which meant I had no idea what it looked like (even though I should have known). This made the third FRQ difficult for me, as I even asked Orlando and we both tried to look for any trace of us using 2D arrays in our FRQ. Additionally, I also combined all my code for the methods FRQ to develop a sorting method in order to determine if a number belonged or didn't belong, this could have been done better if I had written blocks of code one by one like the FRQ had asked.

Clearly, I have a lot more to learn and lot more to practice, especially for the FRQs I struggled in. But I'm interested, and willing to put in the work for next trimester. As a student in trimester 2, I lacked to show many concepts that we learned in class, and I was also not able to perform simple tasks like deploying a backend repository. However, despite the FRQs having the purpose of stressing or frustrating students, I actually found them fun and sort of entertaining, they indirectly helped me link all the concepts we learned in class, and I was able to identify the code we had done in our projects instantly.

As Trimester 3 comes up, I think I'm going to consistently reference the four important FRQs when developing new features for PLACE. By being up to date, and knowing how each project aspect relates to what portion of the FRQ, I believe I will be much more prepared for the AP exam, and I hope, a better programmer.

nVarap commented 8 months ago

Crossover Grading

Grader: Varaprasad Nibhanupudi

FRQ Grade Comments
1 0.88/0.9*1.125 = 0.99 Doesn't answer the exact questions, but covers more of what is intended close, just really a different class name. For FRQs in the future, remember to answer the actual FRQs
2 0.83/0.9*1.125 = 0.93 Demonstrated a poker hand guessing. Similar in idea to what is required (guessing game) but doesn't fully show understanding of the Collegeboard requirements for stringbuilding. Hence, lower score given.
3 0.9/0.9*1.125 = 1 Did everything as intended, included a little reflection. Described correct implementation for sparse arrays, including but not limited to how the getters and setter worked, as well how array lists were used.
4 0.9/0.9*1.125 = 1 Did everything as intended, included a little reflection. Discussed how interfaces were used in the creation of number groups, and understood how the range function interacted with everything else.
Association 3.7/3.6 Did extra integration, looking for ways to add 2D arrays into their project, used ChatGPT to visualize a possible solution that may be integrated
FRQ Total 3.92/3.6 FRQs have overall some inconsistency, but generally each necessary benchmark is met.
Total 7.62/7.2 Good work overall! Really liked the poker hand code, but that didn't match up, appreciated understanding what you could possibly integrate into your project.