AP CSA Tri 1 Final
A reflection on my Tri 1 AP CSA MC Final
Notes/Homework Unit 1-6
Unit 1: Primitives (our lesson)
- Two main types of data in java: primitives (int, boolean, char, double) and objects (Strings, other classes)
- Primitives can be compared with == while for classes it is necessary to use the .equals() method
- Primitives do not have methods and properties while these are present in classes (ie. String length() method)
- Homework N/A (since we were assigned to present this)
- Objects are just an instance created out of a class created w/ a constructor (which takes in parameters describing the object
- Methods in objects can be void (returns nothing) or have a return type specified
- Static methods and properties are tied to class rather than object (ie. same value for all objects)
- Methods can be overloaded (have different sets of parameters) as long as order of types differs between method definitions even with same name
-
Homework
- Booleans store a true/false value (can only be one of these)
- Booleans can be generated using comparison expressions (equal/==, greater than/>, less than/<, etc.)
- If statements take in a boolean or boolean expression and run if the expression evaluates to “true”
- Else & Else if statements can be used in conjunction with if statements to run code if the if statement evaluates to false
- De Morgan’s Law:
!(a && b) = !a || !b
AND!(a || b) = !a && !b
(ie. distribute and switch the middle sign) -
Homework
- While loop runs while a boolean condition is true (be careful with infinite loops!)
- For loops create a variable which is modified on every loop iteration and has an end condition (useful for iterating through arrays, especially in different ways based on the modification, ie. i += 2 for all even indexes)
- For & while loops can be nested inside each other to achieve more iteration (really useful with 2D arrays)
- For each/Enhanced for loops really useful for looping through an array (int val : array) but limited in that they go through all elements from first to last and that cannot be modified
-
Homework
- Classes can be used for creating objects and have two main things: properties and methods
- Properties are used to store information about each object of a class (can be made private/public which determines accessibility outside of class)
- Methods are used to modify the object & do things
- Getter and Setter Methods can be used to modify properties of a class which are made private
-
Homework
- Arrays can be created by creating a new object (
new type[size]
) or by the initialization syntax ({elem1, elem2, elem3}) - Arrays can be traversed using for loop (using array length as end condition) or using a enhanced for loop
- Be careful with arrays to not go out of bounds (0..array.length-1) or you will get ArrayIndexOutOfBoundsException
- Arrays can be used in combination with many algorithms such as sum, max, # of even/odd, etc.
- Homework
MC Score
- My final score was 37/40, and I was pretty happy with this score as it would translate to a 5 on the AP Exam if I did decent on the FRQs and meant I got over a 90% on this.
MC Mistakes & Reflections
Question 15
- I thought that
I
andII
were correct code that achieved the objective as they both had a for loop and compared adjacent elements to see if they were sorted - I did not notice that for
II
, whenk
isdata.length-1
, the if statement will checkdata[data.length]
anddata[data.length-1]
- Since the indexes of the array range from 1..data.length-1, checking
data[data.length]
will throw an out of bounds exception
- Since the indexes of the array range from 1..data.length-1, checking
- This means only
I
was correct and therefore answer choiceA
was correct
Question 26
- I thought that
C
was correct because it correctly used an enhanced for loop to traverse the array and checked if the element was odd correctly - The mistake with this answer choice was that it printed
arr[x]
utilizingx
as an index- This is incorrect since in an enhanced for loop,
x
actually represents the value in the array rather than an index
- This is incorrect since in an enhanced for loop,
- This means the correct answer choice was
A
which was identical toC
but replacedarr[x]
withx
Question 30
- I thought that
B
was the correct answer as I reasoned that it would first take the characters from index3
to the end (“plier”), and then add the rest of the word (“com”) - I neglected to see that in the question the first substring was using
howFar + 1
instead ofhowFar
as the starting index- This means the first string would be “lier” instead of “plier” making the answer “liercom”
- This leads to the correct answer being
C
Overall Reflections
- I felt pretty good about all the concepts covered as most of my mistakes were silly mistakes
- In order to improve my score further I could focus on reading the question and answer choices more closely because that is where most of my mistakes came from