Emaad-Mir / emaad-github-pages1

MIT License
0 stars 0 forks source link

CSA 2015 FRQs + Association Between FRQs and Our Project #12

Open Emaad-Mir opened 6 months ago

Emaad-Mir commented 6 months ago

Association Between FRQs and Our Project

FRQ 1 (Arrays/ArrayLists + 2D Arrays)

This question from this FRQ has three parts (A, B, and C) and they all centered on both one and two dimensional arrays of integers. Whereas part A focused just one one dimensional arrays, part b and c were questions that emphasized writing methods for two dimensional arrays. For our ASL project, we have many instances of using ArrayLists, such as the ones we used to create the Frames API controller as shown below:

// FrameApiController.java
 private List<List<Integer>> convertToMNIST(String imageData) {
        try {
            byte[] imageBytes = Base64.getDecoder().decode(imageData);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
            BufferedImage image = ImageIO.read(bis);

            BufferedImage resizedImage = new BufferedImage(28, 28, BufferedImage.TYPE_BYTE_GRAY);
            Graphics2D g = resizedImage.createGraphics();
            g.drawImage(image, 0, 0, 28, 28, null);
            g.dispose();

            List<List<Integer>> mnistData = new ArrayList<>();
            for (int y = 0; y < 28; y++) {
                List<Integer> row = new ArrayList<>();
                for (int x = 0; x < 28; x++) {
                    int pixel = resizedImage.getRGB(x, y) & 0xFF;
                    row.add(pixel);
                }
                mnistData.add(row);
            }
            return mnistData;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

To sum up what this code segment is doing, the convertToMNIST method uses an ArrayList to represent an image pixel's values in a 2D structure. The outer ArrayList, mnistData, stores each row of the image as an inner ArrayList of integers, where each integer represents the grayscale intensity of a pixel. Similar to FRQ 1, this segment iterates over the pixels of a resized 28x28 image, converting each pixel's intensity to an integer, and organizing these into rows and columns to mimic the format required by MNIST dataset-compatible models. This is what ultimately allowed us to see our database in the backend filled with a long list of numbers corresponding to the pixel's intensity.

This code segment is similar to the first FRQ here in that they both required iteration through a list of integers. The FRQ required iteration in order to calculate the sum of one and two dimensional arrays and the Frames API controller needed iteration in order to convert each pixel's greyscale intensity into an integer.

FRQ 2 (Classes)

Question 2 from this FRQ had just one part, which asked students to write the entire hiddenWord class in order to model a game that is quite similar to Wordle. This question required several if statements to be able to answer it, as there needed to be different outputs depending on if the user guessed a correct letter in the correct place, guessed a correct letter in the wrong place, or just guessed a letter that was not in the word. Our ASL project as expected had several classes as well as if statements within those classes, with one example being the LeaderboardApiController class as shown below:


// LeaderboardApiController.java
@RestController
@RequestMapping("/api/leaderboard")
public class LeaderboardApiController {

    @Autowired
    private LeaderboardJpaRepository repository;

@GetMapping("/")
public ResponseEntity<List<Leaderboard>> getLeaderboard() {
    List<Leaderboard> leaderboard = repository.findAllByOrderByScoreDesc();
    System.out.println("Fetched leaderboard data: " + leaderboard);
    return new ResponseEntity<>(leaderboard, HttpStatus.OK);
}

@PostMapping("/update/{playerName}/{score}/{streak}")
public ResponseEntity<Leaderboard> updateScoreAndStreak(@PathVariable String playerName, @PathVariable int score, @PathVariable int streak) {
    List<Leaderboard> leaderboardList = repository.findByPlayerNameIgnoreCase(playerName);
    Leaderboard leaderboard;
    if (leaderboardList.isEmpty()) {
        leaderboard = new Leaderboard(playerName, score, streak);
    } else {
        leaderboard = leaderboardList.get(0);
        leaderboard.setScore(leaderboard.getScore() + score); // Add score to existing total
        leaderboard.setRecentStreak(streak); // Update recent streak
    }
    repository.save(leaderboard);
    return new ResponseEntity<>(leaderboard, HttpStatus.OK);
}}

Much like how the FRQ uses if statements to decide what type of character (*, +) to put in place of the letter that the user guessed, the above code segment uses if statements to figure out what to do with the leaderboard once a user has finished the game. If the leaderboard was previously empty and a user just completes a game, they will be added as a new entry to the leaderboard with their name along with the number of points they earned from that game and most recent streak. Otherwise, if the user was already on the leaderboard, the number of points that they earned from their game will be added to their total score on the leaderboard. Their most recent streak will be updated too if it was different from the previous game they played.

FRQ 3 (2D Arrays + Methods and Control Structures)

The third FRQ had a mixture of both 2D Arrays and Control Structures across both parts (A and B) of the question. Part A asked students to write a method that returned the value of something at a specific row and column and part B asked students to write a method that removes a column from the matrix once it is called. While our current ASL project does not implement 2D Arrays that much (which we look forward to including as we head into Trimester 3), it does use several methods and control structures. One example of a method and control structure we used was the receiveDataAndPredict method used in the Predictions API Controller, as shown below:

public ResponseEntity<String> receiveDataAndPredict(@RequestBody List<List<Integer>> mnistData) {

        System.out.println("---------PostMapping");
        String predictionResult = predictionService.predictAndSave(mnistData);
        System.out.println("predictionResult=" + predictionResult);
        return new ResponseEntity<>(predictionResult, HttpStatus.OK);
    }
    return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 
    }

Essentially, the receiveDataAndPredict method takes an image's pixel data (i.e. greyscale intensity), predicts what the image represents (what letter of the alphabet) using a service (predictionService), and returns that prediction to the user and a status code indicating that the request was successfully processed.

Much like how FRQ 3 had a condition of returning an entry's value if the requested row and column indeed had a non zero entry, the code segment above has a condition of returning a specific status code if the request was processed successfully. Overall, this specific implementation of methods and control structures is very similar to that implemented in FRQ 3 in that they both required if and else statements as well as ways of indicating something to be true or false.

FRQ 4 (Interfaces, includes Methods and Control Structures and some Classes)

This question was about creating interfaces, which is technically no longer tested on the AP Exam. However, the question did have topics that continue to be relevant for the AP Exam, making this question important for me to practice on to ensure that I am well prepared of the upcoming AP Exam. Classes were definitely involved in this question, as key words such as "implements" were used to show that the MultipleGroups class is also a NumberGroup class. Methods and control structures were also used here, with the contains method determining if a certain number fell within the test range used for the runtime version. We implement something similar to this in our project in the JPA Repository for the leaderboard shown below:

// LeaderboardJpaRepository.java

public interface LeaderboardJpaRepository extends JpaRepository<Leaderboard, Long> {
    List<Leaderboard> findAllByOrderByScoreDesc();
    List<Leaderboard> findByPlayerNameIgnoreCase(String playerName);
}

Although this code segment is shorter compared to the other examples shown, it still was important in making sure that the leaderboard was sorted in order of highest points to lowest points. What separates our implementation from what FRQ 4 uses is the fact that the key word in our project is "extends" while the key word in the question was "implements". While extends is used to extend a class's existing functionality, implements is used to include attributes of an interface in your class. Overall, though, both implementations demonstrate the important concept of inheritance for classes and how they all end up working together to achieve a desired functionality.

Reflection/Key Takeaways/Observations

jm1021 commented 6 months ago

Q1. List of List is certainly a 2D structure. Just of reference type, not of primitive type. CB always seems to test on primitive type, which, IMO is for less functional than what you did. BTW, you should have a constant defined for 28... I heard you might need to store something bigger for more accuracy.

Q2. Interesting how you went for class purpose on this one, it is good to think about functionality. Most just translate to POJO vs @RestController.

Q3 A good way to look at usage of 2D arrays is thinking of the purpose of what it is doing. There are usually 10 ways to solve a problem and believe you are looking at that. However, in so doing we should think of how we do things in ROW order or alternately in COL order, how we manipulate elements like you did when performing grey scale.

Q4 Your response, as well as others, inspired me to re-comment this... https://github.com/nighthawkcoders/spring_portfolio/blob/master/src/main/java/com/nighthawk/spring_portfolio/mvc/person/PersonJpaRepository.java

I like your attitude for study FRQs. I am thinking of providing time, but ultimately it is your test to pass with regards to time and paper.

nikhilc3 commented 6 months ago

Issue reflection grade (4/3.6)

FRQ (3.8/3.6)

jm1021 commented 6 months ago

Issue reflection grade (4/3.6)

  • FRQ 1 (Arrays/ArrayLists + 2D Arrays): Implementing 2D arrays for image processing helped emaad get a better understanding of nested data structures and their practical applications beyond theoretical problems.
  • FRQ 2 (Classes): Creating classes for his project's API controllers helped him with hands-on experience in OOP and this is showing the importance of class design in solving hard problems.
  • FRQ 3 (2D Arrays + Methods and Control Structures): Working with methods and control structures in the context of 2D arrays showed how adaptive these constructs in manipulating data structures are for specific outcomes.
  • FRQ 4 (Interfaces, includes Methods and Control Structures and some Classes): The use of interfaces and the implementation relationship in his project helped him appreciate the power of abstraction and polymorphism in creating flexible and reusable code.
  • Overall he had a very good association with his project to the FRQ, and could see how PBL has most definitely enhanced his learning.

FRQ (3.8/3.6)

  • Was very detailed in each of the FRQ and was formatted well. Had the college board answer and the code block running. Also had a detailed reflection going into the code explaining the overall concept of the frq for example number 2 he talked about how the problem was a classes type question. He also went through each of the thought processes of each one which gets a good idea of how he is thinking. He did this for every single FRQ, with the same theme of doing how you would answer on college board, then the run-able code in a cell, and then reflection.

This review is confusing to me. FRQs should be more like a checklist. Did they meet objectives of CB (review requirements like Luna on Raymond) and of Teacher (does it run, in notebook, all methods implemented).

Second part should be more like style above. But, it should contain classic glows/grows, or something you found interesting.