AniCricKet / musical-guacamole

Blog used for AP Computer Science A journey
https://anicricket.github.io/musical-guacamole/
MIT License
0 stars 0 forks source link

CSA 2015 FRQs to PBL Association #13

Open AniCricKet opened 4 months ago

AniCricKet commented 4 months ago
Links to my FRQ question breakdowns: FRQ Submenu Link
FRQ 1 Link
FRQ 2 Link
FRQ 3 Link
FRQ 4 Link

Question 1: The first FRQ was about Arrays/Array Lists, specifically checking weather they are diverse or not. There are lots of use cases of this in our project. One such case is when the teacher is creating an assignment. We can use both 1D arrays and array lists to store the names of assignments, and we should always check to see if there's an existing assignment with the same name.

Here's an example with 1D arrays

public class AssignmentManager {

    private static final int MAX_ASSIGNMENTS = 100;
    private String[] assignmentNames = new String[MAX_ASSIGNMENTS];
    private int nextIndex = 0;

    public void addAssignment(String assignmentName) {
        // Check for diversity before adding
        if (!isAssignmentNameAlreadyUsed(assignmentName)) {
            // Add the assignment if diverse
            assignmentNames[nextIndex] = assignmentName;
            nextIndex++;
        } else {
            // Handle duplicate assignment names
            System.out.println("Assignment name already exists. Please choose a different name.");
        }
    }

    public boolean isAssignmentNameAlreadyUsed(String newAssignmentName) {
        for (int i = 0; i < nextIndex; i++) {
            if (assignmentNames[i] != null && assignmentNames[i].equals(newAssignmentName)) {
                // Assignment name already exists
                return true;
            }
        }
        // Assignment name is diverse
        return false;
    }

    public static void main(String[] args) {
        AssignmentManager manager = new AssignmentManager();

        // Example of adding assignments
        manager.addAssignment("Homework 1");
        manager.addAssignment("Lab 1");
        manager.addAssignment("Homework 2");
        manager.addAssignment("Project 1");
    }
}

And here's an example using an ArrayList:

import java.util.ArrayList;

public class AssignmentManagerWithArrayList {

    private ArrayList<String> assignmentList = new ArrayList<>();

    public void addAssignment(String assignmentName) {
        // Check for diversity before adding
        if (!assignmentList.contains(assignmentName)) {
            // Add the assignment if diverse
            assignmentList.add(assignmentName);
        } else {
            // Handle duplicate assignment names
            System.out.println("Assignment name already exists. Please choose a different name.");
        }
    }

    // Other methods and functionalities related to your assignment management system

    public static void main(String[] args) {
        AssignmentManagerWithArrayList manager = new AssignmentManagerWithArrayList();

        // Example of adding assignments
        manager.addAssignment("Homework 1");
        manager.addAssignment("Lab 1");
        manager.addAssignment("Homework 2");
        manager.addAssignment("Project 1");
    }
}

Question 2 - The second FRQ question was based on classes, and was the word guessing game. The user would have to guess the hidden word, and would receive hints based on asterisks or plus signs - depending on whether or not a particular letter they guessed was in the word or not, until they eventually guessed the word correctly. Creating classes is an essential Java skill, and is used essentially everywhere in our projects. One specific way I can incorporate this guessing game logic into our newest feature (the flashcards feature), is to make it so that the student receives the definition of the word and has to guess what the word is. This would help the student study better and fully understand the terms on the flashcards.

import java.util.ArrayList;
import java.util.Scanner;

public class AssignmentManagerWithWordGuess {
    private ArrayList<Flashcard> flashcards = new ArrayList<>();
    private Scanner scanner = new Scanner(System.in);

    public class Flashcard {
        private String term;
        private String definition;

        public Flashcard(String term, String definition) {
            this.term = term.toLowerCase();  // Convert to lowercase for case-insensitivity
            this.definition = definition;
        }

        public String getTerm() {
            return term;
        }

        public String getDefinition() {
            return definition;
        }
    }

    public class WordGuessGame {
        private String targetWord;
        private String guessedWord;

        public WordGuessGame(String targetWord) {
            this.targetWord = targetWord.toLowerCase();  // Convert to lowercase for case-insensitivity
            initializeGuessedWord();
        }

        private void initializeGuessedWord() {
            guessedWord = "*".repeat(targetWord.length());
        }

        public String getGuessedWord() {
            return guessedWord;
        }

        public boolean makeGuess(char guessedLetter) {
            guessedLetter = Character.toLowerCase(guessedLetter);  // Convert to lowercase for case-insensitivity

            boolean letterFound = false;
            StringBuilder newGuessedWord = new StringBuilder(guessedWord);

            for (int i = 0; i < targetWord.length(); i++) {
                if (targetWord.charAt(i) == guessedLetter) {
                    newGuessedWord.setCharAt(i, guessedLetter);
                    letterFound = true;
                }
            }

            guessedWord = newGuessedWord.toString();
            return letterFound;
        }
    }

    // Method to add flashcards to the system
    public void addFlashcard(String term, String definition) {
        Flashcard flashcard = new Flashcard(term, definition);
        flashcards.add(flashcard);
    }

    // Method to play the flashcard game
    public void playFlashcardGame() {
        for (Flashcard flashcard : flashcards) {
            System.out.println("Definition: " + flashcard.getDefinition());

            WordGuessGame wordGuessGame = new WordGuessGame(flashcard.getTerm());

            System.out.println("Guess the term:");
            int maxGuesses = 3;
            int guessesMade = 0;

            while (!wordGuessGame.getGuessedWord().equals(flashcard.getTerm()) && guessesMade < maxGuesses) {
                char guessedLetter = getUserGuess();
                boolean letterFound = wordGuessGame.makeGuess(guessedLetter);

                if (letterFound) {
                    System.out.println("Good guess! Updated word: " + wordGuessGame.getGuessedWord());
                } else {
                    System.out.println("Incorrect guess. Try again. Updated word: " + wordGuessGame.getGuessedWord());
                }

                guessesMade++;
            }

            if (wordGuessGame.getGuessedWord().equals(flashcard.getTerm())) {
                System.out.println("Correct! The term is: " + flashcard.getTerm());
            } else {
                System.out.println("Sorry, you've reached the maximum number of guesses. The correct term was: " + flashcard.getTerm());
            }
        }
    }

    private char getUserGuess() {
        System.out.print("Enter your guess (single letter): ");
        return scanner.next().toLowerCase().charAt(0);
    }

    public static void main(String[] args) {
        AssignmentManagerWithWordGuess manager = new AssignmentManagerWithWordGuess();

        // Example of adding flashcards
        manager.addFlashcard("OOP", "Object-Oriented Programming");
        manager.addFlashcard("GUI", "Graphical User Interface");
        manager.addFlashcard("API", "Application Programming Interface");

        // Example of playing the flashcard game
        manager.playFlashcardGame();
    }
}

Question 3 - FRQ 3 was about 2D arrays, and more specifically sparse arrays. I wasn't too familiar with the concept of sparse arrays prior to this FRQ test, so this is definitely something I need to give more thought about on how we can incorporate it into our project. However here is one quick idea that I had:

import java.util.HashMap;

public class AssignmentManagerWithSparseArray {

    public class SparseArray {
        private HashMap<String, HashMap<String, Integer>> sparseArray;

        public SparseArray() {
            sparseArray = new HashMap<>();
        }

        public void setGrade(String studentName, String assignmentName, int grade) {
            sparseArray.computeIfAbsent(studentName, k -> new HashMap<>()).put(assignmentName, grade);
        }

        public int getGrade(String studentName, String assignmentName) {
            return sparseArray.getOrDefault(studentName, new HashMap<>()).getOrDefault(assignmentName, 0);
        }
    }

    private SparseArray gradeArray = new SparseArray();

    // Method to set a student's grade for a specific assignment
    public void setGrade(String studentName, String assignmentName, int grade) {
        gradeArray.setGrade(studentName, assignmentName, grade);
        System.out.println("Grade set for " + studentName + " in " + assignmentName + ": " + grade);
    }

    // Method to get a student's grade for a specific assignment
    public int getGrade(String studentName, String assignmentName) {
        return gradeArray.getGrade(studentName, assignmentName);
    }

    // Example of usage
    public static void main(String[] args) {
        AssignmentManagerWithSparseArray manager = new AssignmentManagerWithSparseArray();

        // Example of setting grades
        manager.setGrade("Aniket Chakradeo", "Homework 1", 95);
        manager.setGrade("Soham Kamat", "Lab 1", 88);

        // Example of getting grades
        int johnGrade = manager.getGrade("Aniket Chakradeo", "Homework 1");
        System.out.println("Aniket's grade in Homework 1: " + johnGrade);

        int janeGrade = manager.getGrade("Soham Kamat", "Lab 1");
        System.out.println("Soham's grade in Lab 1: " + janeGrade);
    }
}

In this example, a sparse array is implemented through the SparseArray class, which efficiently stores grades for students in various assignments. The SparseArray uses a nested HashMap structure, allowing for the dynamic addition and retrieval of grades. The AssignmentManagerWithSparseArray class extends an assignment manager and incorporates the sparse array to set and retrieve grades. The setGrade and getGrade methods interact with the SparseArray instance, enabling the assignment manager to efficiently manage grades by avoiding unnecessary memory allocation for default values. The usage in the main method demonstrates how the AssignmentManagerWithSparseArray class can be employed to set and retrieve grades for specific students and assignments.

Question 4 - The last FRQ placed significant emphasis on methods and control structures. It required a solid understanding of these concepts throughout. Initially, in creating the NumberGroup interface, we developed an interface representing a group of integers, incorporating a "contains" method to check if a given integer belonged to the group. Then, in the Range class, part b demanded the implementation of the contains method. Here, control structures played a key role as conditional statements were employed to determine if an integer fell within the specified range. Lastly, in the MultipleGroups class, which implemented the NumberGroup interface, control structures were utilized to iterate over each NumberGroup, checking if a given integer was present in any of them. This is another topic which I hadn't given too much thought into, as I wasn't sure if it was on the AP test or not. However if we were to incorporate it into our project, we could do something like a system that uses control structures to check weather or not a student has submitted a homework assignment.

import java.util.List;

public class AssignmentManagerWithBasicLogic {

    public interface Assignment {
        boolean isCompleted(Student student);
    }

    public static class Homework implements Assignment {
        private List<String> submittedHomework;

        public Homework(List<String> submittedHomework) {
            this.submittedHomework = submittedHomework;
        }

        public boolean isCompleted(Student student) {
            // Logic to check if the student has submitted the homework
            return submittedHomework.contains(student.getName());
        }
    }

    public static class Project implements Assignment {
        private boolean completed;

        public Project(boolean completed) {
            this.completed = completed;
        }

        public boolean isCompleted(Student student) {
            // Logic to check if the student has completed the project
            return completed;
        }
    }

    public static class Student {
        private String name;

        public Student(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }

    public static class AssignmentManager {
        private List<Assignment> assignments;

        public AssignmentManager(List<Assignment> assignments) {
            this.assignments = assignments;
        }

        public void checkAssignmentsCompletion(Student student) {
            for (Assignment assignment : assignments) {
                if (assignment.isCompleted(student)) {
                    System.out.println(student.getName() + " has completed " + assignment.getClass().getSimpleName());
                } else {
                    System.out.println(student.getName() + " has not completed " + assignment.getClass().getSimpleName());
                }
            }
        }
    }

    public static void main(String[] args) {
        Student student1 = new Student("John");
        Student student2 = new Student("Jane");

        // Homework logic: John has submitted, Jane hasn't
        List<String> submittedHomework = List.of("John");
        Homework homework = new Homework(submittedHomework);

        // Project logic: John completed, Jane not completed
        Project project = new Project(true);

        List<Assignment> assignments = List.of(homework, project);

        AssignmentManager manager = new AssignmentManager(assignments);

        manager.checkAssignmentsCompletion(student1);
        manager.checkAssignmentsCompletion(student2);
    }
}

In this example, we've built a system to manage homework and projects for students using Java. Each type of assignment, represented by the Homework and Project classes, has a method to check if it's completed. For Homework, we check if a student's name is in the list of submitted homework, and for Project, we directly check if it's marked as completed. The AssignmentManager class uses a method that incorporates loops to go through the assignments, applying the completion check method for each and displaying whether a student has completed each assignment or not. This example highlights the use of basic control structures like loops and methods to handle assignment completion in a straightforward manner. Obviously this is a very basic example, and we would have to adjust the logic based on our specific requirements and consider how we would track completion for homework and projects.

Krishiv111 commented 4 months ago

Grading For Association;

FRQ 1; Good knowledge and connections and demonstration and usage within projects , demonstrated storing of values and a checking arrays by index which connected to the FRQ, The index card manager method that he used was a way to index the specific arrays to return a value similar to the FRQ, the implementation of a 1D array coupled with the array list to have the specific values for each card allowed for a similarity array sum.

Score: 1/0.9

FRQ 2: Classes made shown but didn't really have a clean explanation on how the FRQ worked which is where I would dock some points off but had an understanding of the class. Good usage of Flashcard implementing aword guessing class although this is not implemented within his project he talked about the future plans. and connecting the PBL and FRQ through classes and how FRQ's were based on the implementation of something within your grade..

0.9/0.9

FRQ 3: had a good understanding and how did PBL would work towards however didn't implement this specific code rather but talked about what Sparse arrays were and how he could implemet it within his project, there was a clear theme of integration along with the use with remove and adding values through a hashmap 0.9/0.9

FRQ 4 : This Didn't necessarily talk about the specific connections between what interfaces are used for rather just gave an example could be more detailed but had a good example and talked about what they had learned about the specific interface. I liked the connection between and class extension and an interfacehow each FRQ worked to help him get a better understanding of connecting different classes. Makes a seamless transition to how could connect with future plans although isn't yet implemented.

0.9/1 TOTAL: 3.7/3.6

Krishiv111 commented 4 months ago

FRQ 1

Part A: Code Was Executed good and implementation, had a great understanding of the arrays and how they return a sum. Overall Great The array sum method allowed to compute some and executer there values within the array, Part B: Good explanation of how the code would work and how sums and iteration works within an array. The reflection does a good job of explaining of how the values of Part C: Made sense of diversify within the arrays and code ran well all expectation were met and turned in early For the specific FRQ he had implemented correct methods. Great implementation but the code still lacks documentation which is something we can all work on.

Score 1/0.9

FRQ 2

Score 1/0.9

FRQ 3

Part A/B: Had understanding of the sparse array but didn't really have the best explanation of what the function of the sparse array , He could of talked about the approach he took as he told me he didn't understand some parts of the FRQ. This is key with the parts of the FRQ. To improve I would document the code better and talk about the parts he didn't understand and how he is going to improve on his technicals.

Score 0.8/0.9

FRQ 4

1+1+0.8+0.9 = 3.7/3.6

Total 3.7 + 3.7 = 7.4/7.2