Overall Reflection/Takeaways

Overall, there was a lot to takeaway from this trimester. Apart from covering mostly each of college board's 10 units for CSA and other general Java/OOP related topics, PBL covered a wide range of skills and tools that I was able to experience. The main issue for me was time management and separating college board and pbl into manageable parts. Often times I was all over the place w/ CS work. Nevertheless, there was a lot to learn that will both help with my CS knowledge and my future career.

Project Based Learning

PBL was a really good experience especially in understanding what is necessary for full stack. Especially for web development, there was a lot to understand in developing websites and how to use and integrate databases and APIs into my websites. Beyond just web development, I think this trimester's PBL rly helped extend to other aspects of code development in terms of working with teams and employing similar concepts to other applications.

Fastpages

Learning Fastpages helped develop my ability to blog my learning and developments. Fastpages itself was generally very easy to use to develop requiring the creation of notebooks or html/md files. Generally, it seems to be a very useful tool that I can maybe even use in the future outside of CSA.

AWS

Learning AWS enough to use it was a nightmare at first. It still is since many of the files and settings for the aws server wasn't created by me or a teammate. However, it was enough to know how docker creates an image of the code base from a github repo and then runs it on AWS's local machine before finally being managed by nginx as a web url. I also gained a better understanding of how to use linux commands and terminal in general.

Agile

One of the things we learned was the agile programming philosophy. Overall it helped establish how to delegate tasks to other teammates and develop my ability to communicate and accomplish tasks with my teammates.

HTML/JS

Although not a major focus, we learned some HTML and JS which was a decent exposure for me since I had little experience with web development. Having to deal with it however definitely gave me the opportunity to these two vital aspects of web development.

College Board Learning

This covered the 10 units for college board and although we didn't cover all the units, there were a decent amount of CS topics to takeaway.

Methods and Control

Methods and control structures are important tools in building effective code. Not only do they manage the flow of code, they also enable efficient structures for code that can be reproduced for future instances of code.

Primitives

Primitives are the most basic data types of Java and most other programming languages. Although they store small data, they are effective and can be casted to different data types. They are most easily processed by processors and are essential to most programs in a variety of ways.

// 1A
public boolean conflictsWith(Appointment other){
    return getTime().overlapsWith(other.getTime());
}

// 1B
public void clearConflicts(Appointment appt){
    for (int i = 0; i < aptList.size(); i++){
        if (appt.conflictsWith((Appointment)apptList.get(i))){
            aptList.remove(i);
        }
    }
}

// 1C
public boolean addAppt(Appointment appt, boolean emergency){
    if (emergency){
        clearConflicts(appt);
    }

    else{
        for (int i = 0; i < apptList.size(); i++){
            if (appt.conflictsWith((Appointment)apptList.get(i))){
                return false;
            }
        }
    }
    
    return apptList.add(appt);
}

// 2A
public double purchasePrice(){
    return (1 + taxRate) * getListPrice();
} 

// 3A
public int compareCustomer(Customer other){
    int comparedNames = getName().compareTo(other.getName());

    if (comparedNames != 0){
        return comparedNames;
    }

    else{
        return getID() - other.getID();
    }
}

Using Objects

Objects are more complex data types and reflect the Object Oriented Programming paradigm which models the real world's use of objects except with code. It uses classes which are 'blue prints' for the code and then instantiates that class as an 'object'. At its core, it consists of attributes (data/variables) and methods.

public class Goblin {
    private String name;
    private int HP;
    private int DMG;
    private double hitChance;
    private double criticalHitChance;

    public String getName() {
        return name;
    }

    public int getHP() {
        return HP;
    }

    public int getDMG() {
        return DMG;
    }

    public double getHitChance() {
        return hitChance;
    }

    public double getCriticalHitChance(){
        return criticalHitChance;
    }

    public boolean isAlive() {
        if (this.HP > 0) {
            return true;
        } else {
            return false;
        }
    }

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

    public void setHP(int newHP) {
        this.HP = newHP;
    }

    public void takeDMG(int takenDamage) {
        this.HP -= takenDamage;
    }

    public void setDMG(int newDMG) {
        this.DMG = newDMG;
    }

    public void setHitChance(double newHitChance) {
        this.hitChance = newHitChance;
    }

    public void setCriticalHitChance(double newCriticalHitChance) {
        this.criticalHitChance = newCriticalHitChance;
    }
}
import java.lang.Math;

public class Duel {

    public static void attack(Goblin attackerGoblin, Goblin attackeeGoblin) {

        System.out.println(attackerGoblin.getName() + " attacks " + attackeeGoblin.getName() + "!");
        if (Math.random() < attackerGoblin.getHitChance()) {
            if (Math.random() < attackerGoblin.getCriticalHitChance()){
                attackeeGoblin.takeDMG(2*attackerGoblin.getDMG());
                System.out.println(attackerGoblin.getName() + " lands a critical hit!");
                System.out.println(attackeeGoblin.getName() + " takes " + 2*attackerGoblin.getDMG() + " damage");
            }
            else{
                attackeeGoblin.takeDMG(attackerGoblin.getDMG());
                System.out.println(attackerGoblin.getName() + " hits!");
                System.out.println(attackeeGoblin.getName() + " takes " + attackerGoblin.getDMG() + " damage");
            }   
        } else {
            System.out.println(attackerGoblin.getName() + " misses...");
        }

        System.out.println(attackeeGoblin.getName() + " HP: " + attackeeGoblin.getHP());
        System.out.println();
    }

    public static void fight(Goblin goblin1, Goblin goblin2) {
        while (goblin1.isAlive() && goblin2.isAlive()) {
            
            attack(goblin1, goblin2);

            if (!goblin1.isAlive()) {
                System.out.println(goblin1.getName() + " has perished");
                break;
            }

            attack(goblin2, goblin1);

            if (!goblin2.isAlive()) {
                System.out.println(goblin2.getName() + " has perished");
                break;
            }
        }
    }

    public static void main(String[] args) {
        Goblin goblin1 = new Goblin();
        goblin1.setName("jeffrey");
        goblin1.setHP(12);
        goblin1.setDMG(2);
        goblin1.setHitChance(0.50);
        goblin1.setCriticalHitChance(0.05);

        Goblin goblin2 = new Goblin();
        goblin2.setName("Gunther the great");
        goblin2.setHP(4);
        goblin2.setDMG(1);
        goblin2.setHitChance(1);
        goblin1.setCriticalHitChance(0.25);

        fight(goblin1, goblin2);
    }
}

Duel.main(null);

Boolean and If/Else Statements

Booleans are important data types which manage simple true or false. This helps manage simple conditions which are used for conditional statements like if/else or loops. If/else statements are vital to code and managing conditions in our code to execute either or sequences of code.

// 2009 3B
public int getChargeStartTime(int chargeTime){
    int startTime = 0;
    for (int i = 1; i < 24; i++){
        if (this.getChargingCost(i, chargeTime) < this.getChargingCost(startTime, chargeTime)){
            startTime = i;
        }
    }
    
    return startTime;
}

// 2017 1B
public boolean isStrictlyIncreasing(){
    for (int i = 0; i < digitList.size()-1; i++){
        if (digitList.get(i).intValue() >= digitList.get(i+1).intValue()){
            return false;
        }
    }
    
    return true;
}

// 2019 3B
public boolean evaluateLight(int row, int col) {
    int onInCol = 0;
    for (int r = 0; r < lights.length; r++) {
        if (lights[r][col]) {
            onInCol++;
        }
    }
    
    if (lights[row][col] && onInCol % 2 == 0) {
        return false;
    } else if (!lights[row][col] && onInCol % 3 == 0) {
        return true;
    } else {
        return lights[row][col];
    }
}

Iteration

Iteration is important for looping sections of code and manages the complexity of such code. There are 3 main types of loops being for while and recursion. This is an important way to iterate through code multiple times.

public class Guessing {
    static int b = randomNumber();
    static boolean gameRunning = true;
    public static int randomNumber() {
        
        double a = (1 + Math.random() * 100);
        return ((int) Math.floor(a));
    }
   
    public static void newNumber(){
        b = randomNumber();
    }

    public static String guessing(String guess) {
        int c = Integer.valueOf(guess);
        
        if (c != b) {
            if (c > b) {
                return (c + " was not the number," + "\nlower\n");
            }
            if (c < b) {
                return ( c + " was not the number," + "\nhigher\n");
            }
                
        }

        if (c == b) {
            gameRunning = false;
            return "You guessed it! The number was " + b;
        }

        return "error";
   }
}

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(Guessing.gameRunning){
            System.out.println("Type Guess Here: ");
            String input = scanner.nextLine();
            System.out.println(Guessing.guessing(input));
        }
    }
}

Main.main(null);

Writing Classes

Writing Classes is important since the definition of classes defines the properties of objects and the functions of the class itself. This in turn can be used to build complex templates of code. Among the most important aspects of classes are getters, setters, and constructors which are essential to classes.

No homework since it was our presentation.

Array

Arrays are a useful way to group data. It acts as a container of data (primitives, objects, etc.) and can easily be mutated.

// Write array methods for the Array Methods class below out of the options given above.
public class ArrayMethods {
    private int[] values = {1, 2, 3, 4, 5, 6, 7, 8};

    public void printElements(){
        for(int i = 0; i < values.length; i++){
            System.out.println(values[i]);
        }
    }

    public void swapElements(){
        int lastElement = values[values.length-1];
        values[values.length-1] = values[0];
        values[0] = lastElement;
    }

    public void replaceAllZero(){
        for(int i = 0; i < values.length; i++){
            values[i] = 0;
        }
    }

    public static void main(String[] args){
        
        System.out.println("First and Last Element Swap: ");
        ArrayMethods swapElements = new ArrayMethods();
        swapElements.swapElements();
        swapElements.printElements();

        System.out.println("Replacing All Elements w/ Zero: ");
        ArrayMethods replaceAllZero = new ArrayMethods();
        swapElements.replaceAllZero();
        swapElements.printElements();
    }
}

ArrayMethods.main(null);