Tirth-Thakkar / Mort-Pages-Personal

My own personal mort pages blog, for Computer Science A based on the Nighthwak Pages template.
https://tirth-thakkar.github.io/Mort-Pages-Personal/
MIT License
0 stars 0 forks source link

Trimester 2 Final Exam #8

Open Tirth-Thakkar opened 7 months ago

Tirth-Thakkar commented 7 months ago

PBL VS FRQ

General Information

Question 4: Methods and Control Structures

In the fourth FRQ there was a focus on the use of interfaces and the creation of interfaces that serve as a basic template for all future similar occurrences of a class. We have a similar implementation within our own project representing a similar overall concept that we used an interface to define the basic structure of any crop and the methods that they would typically have, along with soil additives and the methods that they would typically have. In the FRQ, we made an interface for NumberGroup that serves as a template for all future NumberGroup classes such as Range where the shared method contains is overridden. In our code, we can see a similar pattern where SoilAdditive methods are overridden in Glyphosate and Crop methods in Corn in order to accomplish their unique attributes and methods while retaining the overall structure as provided by the interface.

public interface Crops {
    int econValue(int area);
    int growthStage();
    int calculateGrowingSeason();
    int profitValue(int area);
    int waterUsage(int area);
}

public interface SoilAdditives {
    int cost(int area);
    int ecoEffect(int area);
    int growthEffect(int area);
    int profitEffect(int area);
}

Question 2: Classes

In the second FRQ, there was a focus on the definition of classes and the constructor needed to initiate the class, like in HiddenWord class where we defined a constructor to take in the needed String and set it to the instance variable. We have a similar implementation within the Glyphosate class that we used a constructor to initiate the class and set the instance variable of area to perform the calculations to scale cost with the amount used. We can also see this in a general trend throughout other aspects of our project where we define the Inventory class, Corn class, Person class, etc.

// Uses the interface SoilAdditives element to implement the Glyphosate class like question 4
// The definition of the Glyphosate class similar to the concepts of question 2 
public class Glyphosate implements SoilAdditives {

    int cost = (int) (Math.random() * 13) + 1; // Glphosate cost's between 1 and 13 dollars per 
                                               // acre so we pick a random number in 
                                               // this range to get the cost
    int ecoEffect = -10;
    int growthEffect = 10;
    int profitEffect = 2;
    int area;

    public Glyphosate(area) {
        this.area = area;
    }

    @Override
    public int cost(int area) {
        int quantity = area;
        int unitCost = this.cost;
        int totalCost = unitCost * quantity;
        return totalCost;
    }

    @Override
    public int ecoEffect(int area) {
        int quantity = area;
        int unitEcoEffect = this.ecoEffect;
        int totalEcoEffect = unitEcoEffect * quantity;
        return totalEcoEffect;
    }

    @Override
    public int growthEffect(int area) {
        int quantity = area;
        int unitGrowthEffect = this.growthEffect;
        int totalGrowthEffect = unitGrowthEffect * quantity;
        return totalGrowthEffect;
    }

    @Override
    public int profitEffect(int area) {
        int quantity = area;
        int unitProfitEffect = this.profitEffect;
        int totalProfitEffect = unitProfitEffect * quantity;
        return totalProfitEffect;
    }
}

Question 1: 2D Arrays

In question 1 there was a focus on array and 2d array operations where we can use loops to be able to access the various elements from within the array. This was a very common theme regardless of whether the array was 2d or 1d as seen through parts A-C where we used them to perform calculations, like summing up the values in part A or creating the array of row sums in part B, and the nested loops in part C. We have an implementation that also uses this mechanic of dealing with 2d arrays where we create a 2d array of the size growing season with the growing season amount of elements, where we then use nested for loops populate these arrays with values between the growth stage * water usage /2 and growth stage * water usage inclusive, then randomly select an index to create a price, and the shared ability of indexing and accessing the various elements within the 2d array a pattern also seen within the FRQ. This allows us to have an engaging and semi-random experience for the user profits to be able to simulate some of the variability in crop prices which can depend on many factors like moisture content and the amount of crops produced in this game setting.

import java.lang.Math;
import java.util.Random;

// Uses the interface element Crops to implement the Corn class like question 4
public class Corn implements Crops {

    int initialWeek;
    int week;
    int developmentStage;

    public Corn(int initialWeek, int week) {
        this.initialWeek = initialWeek;
        this.week = week;
    }

    @Override
    public int econValue(int area) {

        // creates a matrix of the size of the current week of the growing season then
        // populate it with random values between the growth state * waterusage/2 to
        // growth state * water usage and then pick a random value from the matrix.
        // Use of 2d arrays like question 1
        int growthStage = growthStage();
        int waterUsage = waterUsage(area);
        int growingSeason = calculateGrowingSeason();

        int[][] econValueMatrix = new int[growingSeason][growingSeason];

        Random random = new Random();

        for (int i = 0; i < growingSeason; i++) {
            for (int j = 0; j < growingSeason; j++) {
                int minValue = growthStage * waterUsage / 2;
                int maxValue = growthStage * waterUsage;
                econValueMatrix[i][j] = minValue + random.nextInt(maxValue - minValue + 1);
            }
        }

        int randomValue = econValueMatrix[random.nextInt(growingSeason)][random.nextInt(growingSeason)];
        return randomValue;
    }

    public int calculateGrowingSeason() {
        // Calculate growing season based on current week
        int currentWeek = getCurrentWeek(); // Replace with actual implementation
        int midPoint = 26; // Midpoint of the growing season
        int earlySeasonDebuff = 2; // Debuff for being too early in the season
        int lateSeasonDebuff = 1; // Debuff for being too late in the season

        if (currentWeek < midPoint) {
            return earlySeasonDebuff * (midPoint - currentWeek);
        } else {
            return lateSeasonDebuff * (currentWeek - midPoint);
        }
    }

    private int getCurrentWeek() {
        // Replace with actual implementation to get the current week
        return this.week;
    }

    @Override
    public int growthStage() {
        // get week via request from FE
        double randNum = 2 + (Math.random() * 4); // generates a random number between 2 and 5
        int weekGrowthFactor = (int) (randNum);
        int developmentStage = this.developmentStage;
        int initialWeek = this.initialWeek; // week when corn was placed
        int week = this.week;
        if (week - initialWeek == weekGrowthFactor) {
            developmentStage = developmentStage + 1;
        }
        return developmentStage;
    }

    @Override
    public int profitValue(int area) {
        int waterNeeded = waterUsage(area);
        int waterCost = 10; // 10 dollars allows for 1000 gallons of water
        int totalWaterCost = waterCost * waterNeeded;
        int baseCropProfit = 6134;
        int totalProfit = baseCropProfit - totalWaterCost;
        return totalProfit * area; // 134 dollars profit
    }

    @Override
    public int waterUsage(int area) {
        // 1 unit = 1000 gallons of water
        int waterNeeded = 600;
        return waterNeeded * area;
    }
}

Question 3: Array List

In question 3 there was a focus on arrayList through the SparseArray class which has an arrayList labeled entries which was full of SparseArrayEntry objects where we wanted to be able to operate on this arrayList to find the populated indices of the SparseArray represented and to be able to remove all elements of a given column and adjust the array size and indices of the remaining elements. We have similar properties in our Inventory class where the class contains an ArrayList of either SoilAdditive or Crop objects representing the user's use and quantity of these objects, the use of the ArrayList allows us to similarly adjust the contents of the user's inventory like we did in the problem like adding and removing the elements which would resize their inventory, and not being of a fixed size. From this, we can then also perform operations based on the contents of their inventory and get readouts for their overall statistics from water usage, to total farm growth rate, etc similar to the problem and the ability for us to create the getValueAt() method from the data stored within the array list. Which we then achieve by creating an Inventory object for each user and then editing the Crops and soilAdditives dynamically as they play the game.

import java.util.ArrayList;
import java.util.List;

public class Inventory {
    private List<Crops> cropsList;
    private List<SoilAdditives> soilAdditivesList;
    private int farmArea;
    // Similar to FRQ 3 we have an array list that a player holds in their inventory
    // this also allows us for us to add and change elements as they
    // go through out the game ensuring more flexibility, we are also looping
    // through the various elements and being able to get a more
    // in-depth amount of player stats

    public Inventory(int farmArea) {
        cropsList = new ArrayList<>();
        soilAdditivesList = new ArrayList<>();
        this.farmArea = farmArea;
    }

    public void addCrop(Crops crop) {
        cropsList.add(crop);
    }

    public void removeCrop(Crops crop) {
        cropsList.remove(crop);
    }

    public void addSoilAdditive(SoilAdditives soilAdditive) {
        soilAdditivesList.add(soilAdditive);
    }

    public void removeSoilAdditive(SoilAdditives soilAdditive) {
        soilAdditivesList.remove(soilAdditive);
    }

    public int getEconValue() {
        int totalEconValue = 0;
        for (Crops crop : cropsList) {
            totalEconValue += crop.econValue(farmArea);
        }
        return totalEconValue;
    }

    public int getGrowthStage() {
        int totalGrowthStage = 0;
        for (Crops crop : cropsList) {
            totalGrowthStage += crop.growthStage();
        }
        return totalGrowthStage;
    }

    public int getProfitValue() {
        int totalProfitValue = 0;
        for (Crops crop : cropsList) {
            totalProfitValue += crop.profitValue(farmArea);
        }
        return totalProfitValue;
    }

    public int getWaterUsage() {
        int totalWaterUsage = 0;
        for (Crops crop : cropsList) {
            totalWaterUsage += crop.waterUsage(farmArea);
        }
        return totalWaterUsage;
    }

    public int getCost() {
        int totalCost = 0;
        for (SoilAdditives soilAdditive : soilAdditivesList) {
            totalCost += soilAdditive.cost(farmArea);
        }
        return totalCost;
    }

    public int getEcoEffect() {
        int totalEcoEffect = 0;
        for (SoilAdditives soilAdditive : soilAdditivesList) {
            totalEcoEffect += soilAdditive.ecoEffect(farmArea);
        }
        return totalEcoEffect;
    }

    public int getGrowthEffect() {
        int totalGrowthEffect = 0;
        for (SoilAdditives soilAdditive : soilAdditivesList) {
            totalGrowthEffect += soilAdditive.growthEffect(farmArea);
        }
        return totalGrowthEffect;
    }

    public int getProfitEffect() {
        int totalProfitEffect = 0;
        for (SoilAdditives soilAdditive : soilAdditivesList) {
            totalProfitEffect += soilAdditive.profitEffect(farmArea);
        }
        return totalProfitEffect;
    }

    public int userProfit() {
        return getProfitValue() * getProfitEffect() - getCost();
    }

    public int userEco() {
        return getEconValue() * getEcoEffect();
    }

    public int userGrowth() {
        return getGrowthStage() * getGrowthEffect();
    }

    public int userWater() {
        return getWaterUsage();
    }

}

General Reflections

Solutions to FRQ's + FRQ Reflections

Question
FRQ 1: 2D Arrays
FRQ 2: Classes
FRQ 3: Array Lists
FRQ 4: Methods And Control Structures
jm1021 commented 7 months ago

I like that you organized things in order, Q4 followed by Q2. This show great understanding and direct match of concepts in your work.

Looks like a perfect usage of interface. I liked that you used @Overrides to show with perfect clarity that they are defining something either abstract or overriden.

On Q1 I had a little more disappointment in code viewing I would have added JavaScript that is rendering growing season to show the growing season.

Q2 shows great definitions of List with new ArrayList implementations in constructor.


I hear you on instruction parts, but there are many unintended consequences of that path.

For instance, "point focus", "copying" as work is same, "answer focus" vs "learning focus". In truth, knowing that delete in middle of an ArrayList impact iteration is really understood when you apply it or get a tricky FRQ. No one learns this from lecture. I believe even in testing there is a method key for ArrayList, but we need to look it up.

We will have some paper FRQ days over the next 8 weeks. But, I won't be grading them.

VishnuAravind12 commented 7 months ago

FRQ Grading

FRQ 1

FRQ 2

FRQ 3

FRQ 4

VishnuAravind12 commented 7 months ago

Question 4: Methods and Control Structures

Question 2

Question 1

Question 3

jm1021 commented 7 months ago

FRQ Grading

FRQ 1

  • Very Similar to my solution to this problem
  • A) Great understanding of for loops as an iterative structure to sum up the elements of an array.
  • B) Again this problem was very similar to part A, but with the added complexity of an additional dimension. But you did everything correctly, demonstrating a solid understanding of how to traverse the dimensions of 2D Arrays.
  • C) Your code was great, building off previous methods you had coded, and comparing the different sums of each of the rows of the 2D Array. I like that you made a boolean variable to hold whether a 2D Array was diverse or not.
  • Grade: 1.0/0.9

FRQ 2

  • I liked how you modified the passed hiddenWord in the constructor to ensure that all spaces were done away with and all letters were capitalized
  • The class building is great, you have encapsulated the HiddenWord attribute, and have added a constructor and a getter.
  • Your approach is very interesting with the character array and pre filling it out with the *s, and then changing the char array as you build the hint.
  • Grade: 1.0/0.9

FRQ 3

  • Really interesting approach to this problem.
  • Building your SparseArray insde the class itself specifically was pretty interesting
  • You demonstrated great knowledge of working with arrays, and you also were great with class structures (I felt that this problem required a lot of class design).
  • Grade 1.0/0.9

FRQ 4

  • A) Pretty simple here. Great interface.
  • B) Your implementation of the Range is great. And the contains method is correctly overriden and correctly coded. Great work.
  • C) Great work with MultipleGroups. It really shows the power of an interface, its so versatile, and you are not locked in to one type of data object.
  • Grade 1.0/0.9

Very thoughtful assessment. I see you pulling yourself into review, feels like you are investing in this review.

jm1021 commented 7 months ago

Question 4: Methods and Control Structures

  • Comment: Your comparison of the FRQ's focus on interfaces with your project's implementation is well-articulated. The use of interfaces to define common functionalities in different classes, such as Crops and SoilAdditives, is a smart design choice. It shows a clear understanding of interface usage in object-oriented programming.
  • Consideration: While your approach is robust, consider exploring more about how interfaces can enhance polymorphism in your project. This might give you a deeper understanding of designing flexible and scalable systems.
  • Grade 1.0/0.9

Question 2

  • Comment: The explanation of class definitions and constructors is comprehensive. The Glyphosate class demonstrates a clear understanding of how to instantiate objects and set their properties. It’s good to see how concepts from the FRQ have been practically applied in your project.
  • Consideration: Think about discussing the principles of encapsulation and how they could be applied to your class design. For instance, consider whether any class variables should be private and accessed via getter and setter methods.
  • Grade 1.0/0.9

Question 1

  • Comment: Your use of 2D arrays in the Corn class is a great example of handling multi-dimensional data. The implementation of random pricing within a matrix structure is innovative and adds complexity to your project.
  • Consideration: It might be beneficial to explore error handling for array operations. Consider what happens if the array indices go out of bounds, or if the array is not initialized correctly.
  • Grade 1.0/0.9

Question 3

  • Comment: The use of ArrayList in your Inventory class is well executed. It shows a good understanding of dynamic data structures and how they can be manipulated for various operations like adding and removing items.
  • Consideration: Reflect on the efficiency of your ArrayList operations. Consider the time complexity of various operations and whether there are any performance implications, especially as the size of your inventory grows.
  • Grade 1.0/0.9

This is very powerful and classic glows and grows writeup. This gives me ultimate confidence grader is do depth analysis and really interacting with person they are grading.