gwang1224 / Graces-CSA

MIT License
0 stars 0 forks source link

CSA 2015 FRQ Connections to PBL #7

Open gwang1224 opened 8 months ago

gwang1224 commented 8 months ago

FRQ 1

link

This Free Response Question assessed the ability to utilize 1D and 2D arrays, focusing on iterating through them, accessing elements, and employing nested loops and conditional statements to achieve a specific goal—checking the diversity of array elements.

First, we used a 1D array to initialize sign in data. The provided code utilizes an array called persons to store instances of the Person class. This array is initialized with five Person objects, each representing an individual with attributes such as name, email, password, and date of birth. The array enables convenient access and organization of the created Person instances within the program.

// Initialize static test data 
    public static Person[] init() {

        // basics of class construction
        Person p1 = new Person();
        p1.setName("Grace Wang");
        p1.setEmail("gracewang@gmail.com");
        p1.setPassword("123Grace!");
        // adding Note to notes collection
        try {  // All data that converts formats could fail
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("09-02-2005");
            p1.setDob(d);
        } catch (Exception e) {
            // no actions as dob default is good enough
        }

        Person p2 = new Person();
        p2.setName("Alexander Graham Bell");
        p2.setEmail("lexb@gmail.com");
        p2.setPassword("123LexB!");
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("01-01-1845");
            p2.setDob(d);
        } catch (Exception e) {
        }

        Person p3 = new Person();
        p3.setName("Nikola Tesla");
        p3.setEmail("niko@gmail.com");
        p3.setPassword("123Niko!");
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("01-01-1850");
            p3.setDob(d);
        } catch (Exception e) {
        }

        Person p4 = new Person();
        p4.setName("Madam Currie");
        p4.setEmail("madam@gmail.com");
        p4.setPassword("123Madam!");
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("01-01-1860");
            p4.setDob(d);
        } catch (Exception e) {
        }

        Person p5 = new Person();
        p5.setName("John Mortensen");
        p5.setEmail("jm1021@gmail.com");
        p5.setPassword("123Qwerty!");
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("10-21-1959");
            p5.setDob(d);
        } catch (Exception e) {
        }

        // Array definition and data initialization
        Person persons[] = {p1, p2, p3, p4, p5};
        return(persons);
    }

In the context of our cybersecurity educational game website, the provided code serves the purpose of retrieving all game sessions for a specific game. It calculates the minimum session time for each user and generates a sorted leaderboard that ranks users based on their speed in completing the game.

FRQ 2

link

This Free Response Question emphasized Java classes and their essential components, including private instance variables, constructors, and methods. We implemented a HiddenWord class, leveraging Object-Oriented Programming principles and string manipulation techniques to develop a word guessing game.

We used classes in our Person.java to create the signin page:

public class Person {

    // automatic unique identifier for Person record
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    // email, password, roles are key attributes to login and authentication
    @NotEmpty
    @Size(min=5)
    @Column(unique=true)
    @Email
    private String email;

    @NotEmpty
    private String password;

    // @NonNull, etc placed in params of constructor: "@NonNull @Size(min = 2, max = 30, message = "Name (2 to 30 chars)") String name"
    @NonNull
    @Size(min = 2, max = 30, message = "Name (2 to 30 chars)")
    private String name;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date dob;

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

    /* HashMap is used to store JSON for daily "stats"
    "stats": {
        "2022-11-13": {
            "calories": 2200,
            "steps": 8000
        }
    }
    */
    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb")
    private Map<String,Map<String, Object>> stats = new HashMap<>(); 

    // Constructor used when building object from an API
    public Person(String email, String password, String name, Date dob) {
        this.email = email;
        this.password = password;
        this.name = name;
        this.dob = dob;
    }

    // A custom getter to return age from dob attribute
    public int getAge() {
        if (this.dob != null) {
            LocalDate birthDay = this.dob.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            return Period.between(birthDay, LocalDate.now()).getYears(); }
        return -1;
    }

    // Initialize static test data 
    public static Person[] init() {

        // basics of class construction
        Person p1 = new Person();
        p1.setName("Grace Wang");
        p1.setEmail("gracewang@gmail.com");
        p1.setPassword("123Grace!");
        // adding Note to notes collection
        try {  // All data that converts formats could fail
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("09-02-2005");
            p1.setDob(d);
        } catch (Exception e) {
            // no actions as dob default is good enough
        }

        Person p2 = new Person();
        p2.setName("Alexander Graham Bell");
        p2.setEmail("lexb@gmail.com");
        p2.setPassword("123LexB!");
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("01-01-1845");
            p2.setDob(d);
        } catch (Exception e) {
        }

        // Array definition and data initialization
        Person persons[] = {p1, p2};
        return(persons);
    }

    public static void main(String[] args) {
        // obtain Person from initializer
        Person persons[] = init();

        // iterate using "enhanced for loop"
        for( Person person : persons) {
            System.out.println(person);  // print object
        }
    }

}

Here we see all the components of a class. The Person class in this code encompasses various components crucial to modeling person-related data in Java. It features instance variables, such as id, email, password, name, dob, roles, and stats, each holding specific attributes like identification, authentication details, and daily statistics. The class includes constructors, including a parameterless one for basic construction and a parameterized version designed for creating Person objects from API data. Additionally, the class incorporates a custom method, getAge(), to calculate and retrieve the person's age based on the date of birth. The init() static method initializes static test data by creating instances of Person with sample information, and the main method demonstrates the initialization process and prints the objects using an enhanced for loop. Overall, this class employs Object-Oriented Programming principles and uses Java annotations for effective data handling.

FRQ 3

link

This Free Response Question introduced me to the concept of sparse arrays. In simpler terms, I perceive it as a large matrix predominantly filled with zeros, and instead of storing all that memory, you only keep track of the non-zero values (the accompanying illustration greatly aided my visualization). I understand its primary purpose is to efficiently represent and store arrays where most elements have a default value.

We did not include sparse arrays in our PBL project. However, the methods we used could help to store data. For example, in a sparse array, most of the numbers are 0. If we were to implement this in our leaderboard by storing all the scores in an array, if many of the signups did not play the games, their score would be 0, and thus many values in the array would be 0. Then, if the rows are people who sign up, we can see the sum of the scores they got from the games they played. If they have a low sum, we could suggest they do more practice. From the columns of the array, they could be different games. We could see from the scores in each column if each game is too hard or if the game is engaging. If there are low score or scores of 0, the game would be too hard or not fun enough to play, and thus, we could implement a new game.

Screenshot 2024-02-25 at 11 58 34 PM

For example, if this was the sparse array, we would see that individuals 4 and 5 don't really engage with the website and thus we could remove them if there is a lot of inactivity. Moreover, we could see that games 2 and 3 are not played much and new changes could be implemented

FRQ 4

link

In this question, we were working with different computer programming concepts like interfaces, classes, and methods. The goal was to figure out if a number belonged to one or more groups. I learned that in Java, a class can inherit from another class and use multiple interfaces. Interfaces help set up a kind of agreement, saying what a class must do. In our project, we used these ideas, especially with interfaces, for our login feature.

I noticed that all the JpaRepository files contain interfaces

PersonJpaRepository.java

Screenshot 2024-02-26 at 12 05 02 AM

This code extends the Spring Data JPA JpaRepository interface, which, in the context of Java Persistent API (JPA) and Hibernate, facilitates the mapping, storage, updating, and retrieval of data between relational databases and Java objects by defining standard CRUD methods.

GamesessionJpaRepository.java

Screenshot 2024-02-26 at 12 04 07 AM

This interface extends Spring Data JPA's JpaRepository and declares two query methods for retrieving Gamesession entities based on their gameId. These methods provide a convenient and consistent way to interact with the underlying database through the Spring Data JPA repository.

Overall Reflection of FRQ to PBL

FRQs Overall: I thought FRQ 1 was the easiest as I am most familiar with arrays and iterating through each item in the array with for loops. FRQ 2 was also relatively easier because I am familiar with the class frame work. However, when writing the code, I was a bit confused on when to use public and private. It was also challenging to write the code first without testing it, which I will need to learn to get used to for the AP exam. I struggled the most with FRQ 3 and 4, mostly because it was hard to understand the question. The concept in 3 was easier to understand with the sparse arrays, but the instructions for deleting the column was a bit confusing. I had the hardest time with FRQ 4 because I haven't worked with inferences or nested classes, which I will look more into to prepare for the AP test.

Glow:

Grow:

The plan: Watch all the college board videos, do a practice problem set each week (10 weeks until AP CSA test, so that's 10 practice tests!) Learn from a java tutorial and actually learn and enjoy coding in Java (which will be useful for my major in Computer Science)

sreejagangapuram commented 8 months ago

Overall Score 3.8/4

FRQ 1 1/1

FRQ 2 1/1

FRQ 3 0.9/1

FRQ 4 0.9/1

Overall, all outputs are shown and all FRQs are completed. In addition, connections to project show a solid understanding of the frq concepts overall.

sreejagangapuram commented 8 months ago

Reflection/Connections Score: 3.8