Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ap_comp_sci_a [2024/04/11 06:29] – mrdough | ap_comp_sci_a [2024/04/20 05:37] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== AP CSA Study Guide ====== | ====== AP CSA Study Guide ====== | ||
+ | Curly brackets alignment is a bit janky, not fully accurate but it shouldnt affect consumibility of notes | ||
===== Unit 1 – Primitive Types ===== | ===== Unit 1 – Primitive Types ===== | ||
Line 616: | Line 617: | ||
- Loop stops once the condition is false | - Loop stops once the condition is false | ||
- | | + | > |
- | | + | public class Test { public static void main(String[] args) |
+ | { | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
**while Loops and for Loops (continued)** | **while Loops and for Loops (continued)** | ||
Line 624: | Line 633: | ||
* Example of a for loop | * Example of a for loop | ||
- | > public class Test { public static void main(String[] args) { for (int x = 3; x > 0; x--) { System.out.println(x); | + | > public class Test { |
+ | public static void main(String[] args) { | ||
+ | | ||
+ | { | ||
+ | System.out.println(x); | ||
+ | } | ||
+ | | ||
+ | } | ||
* Body of the loops | * Body of the loops | ||
Line 673: | Line 689: | ||
* Example of a nested loop: | * Example of a nested loop: | ||
- | > public class NestedLoops { public static void main(String[] args) { for (int row = 1; row <= 3; row++) { for (int col = 1; col <= 5; col++) { System.out.print(" | + | > public class NestedLoops |
+ | { | ||
+ | public static void main(String[] args) | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
> } } | > } } | ||
Line 737: | Line 764: | ||
* Example of a class: public class Name { | * Example of a class: public class Name { | ||
- | > private String first; private String last; public Name(String theFirst, String theLast) { first = theFirst; last = theLast; } | + | > private String first; |
+ | private String last; | ||
+ | public Name(String theFirst, String theLast) | ||
+ | | ||
+ | | ||
+ | | ||
> } | > } | ||
Line 931: | Line 963: | ||
* Traversing an array with an indexed for loop or while loop expects components to be accessed with their indices. | * Traversing an array with an indexed for loop or while loop expects components to be accessed with their indices. | ||
- | > public class OffByone { public static void main(String[] args) { int[ ] scores = { 10, 9, 8, 7, 6}; | + | > public class OffByone |
+ | | ||
+ | | ||
+ | | ||
+ | int[ ] scores = { 10, 9, 8, 7, 6}; | ||
* Make this loop print out all the scores! for (int i = 1; i <= scores.length; | * Make this loop print out all the scores! for (int i = 1; i <= scores.length; | ||
- | > { System.out.println( scores[i] ); } | + | > { |
+ | System.out.println( scores[i] ); | ||
+ | } | ||
> } } | > } } | ||
Line 1223: | Line 1261: | ||
* Example (part 1) class Human | * Example (part 1) class Human | ||
- | > { private String name; public Human(String theName) { | + | > { |
+ | | ||
+ | | ||
- | > this.name = theName; } public String getName() { return name; } public boolean setName(String newName) { if (newName != null) { this.name = newName; return true; | + | > this.name = theName; |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
* Example (part 2) | * Example (part 2) | ||
- | > } return false; } } public class Employee extends Human { private static int nextEmployeeId = 1; private int employeeId; public Employee(String theName) { super(theName); | + | > } return false; |
+ | } | ||
+ | } | ||
+ | public class Employee extends Human | ||
+ | { private static int nextEmployeeId = 1; private int employeeId; public Employee(String theName) | ||
+ | { super(theName); | ||
- | > } public int getEmployeeId() { return employeeId; } public static void main(String[] args) { Employee emp = new Employee(" | + | > |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | Employee emp = new Employee(" | ||
+ | } | ||
+ | } | ||
**Overriding Methods** | **Overriding Methods** |