Notes

  • Booleans are true or false values
  • Comparison expressions generate booleans
  • If statement run when the conditional evaluates to the boolean true
  • Else if statements take in another conditional after the If statement
  • Else statements runs when the conditional evaluates to false
  • De Morgan's Law: (A∪B)’= A’∩B’, (A∩B)’= A’∪B’

Homework

2009 FRQ 3b

public int getChargeStartTime (int chargeTime) {
    int startHour = 0;
    int lowPrice = 500_000;
    for (int x = 0; x < 23; x++) {
        if (lowPrice > getChargingCost(x, chargeTime)) {
            lowPrice = getChargingCost(x, chargeTime);
            startHour = x;
        }
    }
    return startHour;
}

2017 FRQ 1b

public boolean isStrictlyIncreasing () {
    boolean increasing = true;
    for (int i = 1; i < digitListSize(); i++) {
        if (digitList.get(i-1) >= digitList.get(i)) {
            increasing = false;
        }
    }
    return increasing;
}

2019 FRQ 3b

public boolean isBalanced(ArrayList<String> delimiters) {
    int numOpen = 0, numClosed = 0;
    for(String d : delimiters) {
        if(d.equals(openDel))
            numOpen++;
        if(d.equals(closeDel))
            numClosed++;
        if(numClosed > numOpen)
            return false;
    }
    return numOpen == numClosed;
}