About AP Computer Science A | All posts | Post list
Some more resources for review and practice:
You will prepare for free-response questions with CodingBat problems:
Quiz 7 Sorting Algorithms Practice
26 48 12 92 28 6 33
We will use what you've learned about recursion on some CodingBat problems:
Quiz 4 will be on Monday, November 7th. It will cover for loops for arrays and strings as well as number representations (binary, hexadecimal, octal) and unit testing. Here are some review questions:
int[] arr = {3, 5, 8, 10, 3, 4, 5, 3};
for(int i = 2; i < arr.length-2; i+=3)
{
arr[i] = arr[i] - i + 1;
}
System.out.println(arr[1] +" "+ arr[2] +" "+ arr[4] +" "+ arr[5]);
twoBOrNotTwoB
method with a for
loop to that will return whether the String has exactly two 'b' characters in it.
public boolean twoBOrNotTwoB(String a) {
}
sumMod4Is3
method (with a for
loop) to find and return the sum of all the values x in the given array where x mod 4 is 3. (i.e. if the remainder is 3 when dividing by 4)
public int sumMod4Is3 (int[] c) {
}
squareMultiplesOf5
method (with a for
loop) to modify all the values in the array that are multiples of 5 by squaring them. The method must modify the given array and return the same array. (e.g. if the array is {1,3,4,5,10}
, the modified array would be {1,3,4,25,100}
)
public int[] squareMultiplesOf5(int[] b) {
}
shortestString
method (with a for
loop) to find and return the length of the shortest string in a given array of Strings. (e.g. if the array is {"Halloween","Java","Testing","Number"}
, the method would return 4)
public int shortestString(String[] d) {
}
We will use what you've learned about strings and for loops to solve some more puzzles:
We will use what you've learned about arrays and for loops to solve some more puzzles:
You will write a DragonPokemon
class that is a subclass of the Pokemon
superclass. Here are the things you should include in the DragonPokemon
class:
Pokemon
superclass.attack
method to deal 200 damage instead of 50.dragonRage
that allows them to use the superclass's attack
method to deal damage eight times (for a total of 400 damage) using Dragon Rage, but does not override/overload the attack
method. The hit points of the other Pokemon should be printed out each time it does 50 damage. Use a for loop in this method.public
or private
.Once you are finished with both the Trainer
class and DragonPokemon
class (and you have tested both thoroughly), make sure they are pushed to GitHub.
Hope you enjoyed the Pokemon connection.
Code for the Pokemon class is provided on GitHub.
Now that we have created Pokemon
objects, we need to create some Pokemon Trainers. Use the template for the Trainer
class and implement the variables and methods specified in the comments.
Feel free to modify the test file to thoroughly test all your methods.
Time to solve some more logic puzzles:
For this lab, you will explore some of the basics of NLP. As you explore this, you will work with a variety
of methods of the String
class and practice using the if
statement. You will trace a complicated method to find words in user input.
Get the MagpieLab repository via the link on Slack, which contains the Magpie Student Guide and Starter Code for each of the activities. Clone the forked repository on Codenvy and work on the lab in the Codenvy IDE. Complete each of the exercises and questions. When you are done, make sure to stage, commit, and push your changes to GitHub.
The due date for all the activites is Monday, September 26th. Here is a suggested timeline for completing the lab:
We will use what you've learned about Strings to solve some logic puzzles:
We will use what you've learned about arrays to solve some logic puzzles:
We will use what you've learned about methods and if statements to solve some logic puzzles:
Part 1:
We’re going to take another look at functions and do some math today. Complete this worksheet before moving on to Part 2.
Part 2:
We will now take our multi-variable functions and turn them into multi-parameter methods in Java. Clone the git repository and edit the two Java files in the project: GeometryLab.java
and GeometryLabTest.java
. The first Java file will have your method definitions from the worksheet. The second file will have a main
method with the method invocations/calls from the worksheet and use System.out.println
to print out your answers. Check your answers with the worksheet answers from Part 1.
This program will be called CalendarPrinter
for reasons that will shortly become obvious. Start a new project CalendarPrinter
and clone your git repository. Edit the main
in the Java file to create a program that will produce the below output.
When compiled and executed, your program should output:
September 1
September 2
September 3 – WEEKEND
September 4 - WEEKEND
September 5 – NO SCHOOL (LABOR DAY)
September 6
September 7
September 8
September 9
September 10 – WEEKEND
September 11 – WEEKEND
September 12
September 13
September 14
September 15
September 16
September 17 – WEEKEND
September 18 – WEEKEND
September 19
September 20
September 21
September 22
September 23 - END OF THE MARKING PERIOD
September 24 – WEEKEND
September 25 – WEEKEND
September 26
September 27
September 28
September 29
September 30
Your output should match the above exactly. Observe all capitalization, punctuation, and spacing.
As you might expect, there are some other requirements for writing this program. The most important of these is that you may only have one line of code that calls System.out.println
(and no uses of System.out.print
). Clearly, there is more than one line of printed output. Therefore, you must use a loop and you must use conditionals (if statements) in your program. You must also have at least one String
variable.
cd
to navigate in the terminal to your project folder
git clone URL
cd
to navigate in the terminal to your cloned git repository
public class Hello {
public static void main (String[] args) {
System.out.println("Hello world");
}
}
javac Hello.java
java Hello
git config --global user.email "yourusername@s.sfusd.edu"
git config --global user.name "Your Name"
git status
git add --all
git commit -m "add Hello program"
git push