Unit 4 Assignment
Loops && Algorithms
AP Computer Science 2021-22 / Dr. Kessner
Reading
Coding Bat
Do these exercises on Coding Bat Warmup 2.
- stringTimes
- doubleX
- frontTimes
- stringMatch
- stringSplosion
Note: There is nothing to turn in for this part.
Code
-
Choose two of the above Coding Bat exercises, and implement fully with at least 3 tests each.
-
Implement the following functions, including unit tests. A few example tests are shown (commented). Add at least 2 more tests of your own for each function.
// sumOfSquares(1) -> 1
// sumOfSquares(2) -> 1+4 = 5
// sumOfSquares(3) -> 1+4+9 = 14
// countOccurrences("Mississippi", "iss") -> 2
// countOccurrences("banananana", "na") -> 4
// reverse("bad") -> "dab"
// reverse("Hello, world!") -> "!dlrow ,olleH"
// reverse("tacocat") -> "tacocat"
// factorial(0) -> 1
// factorial(1) -> 1
// factorial(2) -> 2*1 = 2
// factorial(3) -> 3*2*1 = 6
// factorial(4) -> 4*3*2*1 = 24
// factorial(5) -> 5*4*3*2*1 = 120
Note: The Unit 4 Quiz will consist of writing functions involving loop computations, like #2 above, including complete function declarations.