Welcome to AP Computer Science A. If you are a student in the class, the first thing you need to do (and which we should have done in class) is set up your GitHub account.
Once you have a GitHub account, click “Log in to GitHub” below to proceed.
If you don’t have a GitHub account yet, please create one and then log in here for further instructions.
Congratulations! You have successfully connected this app to GitHub. However you are not yet a member of the GitHub organization for this class, something Mr. Seibel needs to set up for you.
This is your GitHub profile URL:
Click the clipboard icon to copy it and then submit it at this form so he can add you.
Congratulations! You have successfully connected this app to GitHub. And it looks like you have an invitation to join the GitHub organization for this class. You need to accept that invitation before you can proceed. The invite should be sent to whatever email you used when you created your GitHub account.
I see you are logged into GitHub and a member of the berkeley-high-cs GitHub organization. However there seems to have been some problem finishing the setup for your account. Please let Mr. Seibel know.
This is a tool for the AP Computer Science A class at Berkeley High School. It is intended to provide a simple environment for experimenting with Javascript without all the complexities of a full development environment such as ReplIt or Glitch which we may use later in the year.
It is also designed to take advantage of the browser’s ability to run Javascript natively. It does not need access to a server to run code making in extremely responsive even if the Wifi is flaking out.
Finally, under the covers it is saving work to a GitHub repository in a very simplified workflow that does not depend on immediately learning any git commands. Code written in this environment for each assignment is saved to a directory and branch specific to that assignment each time it is saved. Thus when the assignment is done, it is easy to go to GitHub and create a PR containing just the work on that assignment which can then be commented on and worked on further before it is turned in and merged to main.
You're all set! You don't need to worry about this yet but we have successfully created a GitHub repository for your work:
You can get to it any time by clicking on your GitHub username at the top-right of the screen.
For a change of pace, this assessment does not require you to write working code though some of the answers will ask you to write bits of code. Instead you will need to read some code and answer questions about it. It is a closed book assessment and you should keep your eyes on your own screen and not talk with your neighbors while you take it. You do not need to submit a pull request this time; your answers are saved automatically when you select from a multiple choice answer or hit enter on a free-form answer.
When this code runs, does it call the foo
method?
int x = 10;
if (x % 2 == 0) {
foo();
}
Yes
No
When this code runs, which methods are called?
int x = 37;
if (x < 37) {
foo(x);
} else {
bar(x);
}
Just foo
Just bar
Both foo
and bar
Neither foo
nor bar
.
When this code runs, which methods are called?
int x = 37;
if (x * -1 < 37) {
foo(x);
}
bar(x);
Just foo
Just bar
Both foo
and bar
Neither foo
nor bar
.
When this code runs, which methods are called?
int x = 37;
if (x < 37) {
foo(x);
} else if (x > 37) {
bar(x);
}
Just foo
Just bar
Both foo
and bar
Neither foo
nor bar
.
In this code:
int x = 0;
for (int i = 0; i < 10; i++) {
x = x + i * 10;
}
what part is the “condition” of the for
loop.
int x = 0
int i = 0
i < 10
i++
x = x + i * 10
Given this definition:
int n = 100;
How many times does the body of this loop execute?
for (int i = 0; i < n; i++) {
// code here
}
99
100
101
Given these definitions:
int start = 13;
int end = 29;
How many times does the body of this loop execute?
for (int i = start; i < end; i++) {
// code here
}
13
14
16
17
29
How many times is the foo
method called when this
code runs:
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
foo(i, j);
}
}
4
30
5
20
12
Given this code:
int c = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < i; j++) {
c++;
}
}
what is the value of c
after the loop finishes?
4
3
6
10
What is the best description of when this loop will stop?
boolean done = false;
while (!done) {
double r = Math.random();
done = r < 0.01;
}
Never, it’s an infinite loop
Immediately, the loop body never executes
When Math.random()
returns a number less that
0.01
When Math.random()
returns a number greater than
0.01
When done
is less than 0.01
In the following code, assume isPrime
is a method
that says whether its argument is a prime number.
public boolean foo(int limit, int max) {
int primes = 0;
for (int n = 2; n < max; n++) {
if (isPrime(n)) {
primes++;
}
if (primes > limit) {
return true;
}
}
return false;
}
Which of the following best describes what this method does?
It tests whether limit
is a prime number.
It tests whether there are at most max
prime
numbers below limit
.
It tests whether there are more than limit
prime
numbers below max
.
It tests whether limit
and max
are
both prime numbers.
Translate this for
loop to an equivalent
while
loop.
for (int i = 0; i < max; i++) {
System.out.println(i);
}
Simplify this method without changing its behavior.
public boolean willGetTakeout(boolean hungry, boolean broke) {
if (hungry && broke) {
return false;
} else if (hungry && !broke) {
return true;
} else if (!hungry && !broke) {
return false;
} else if (!hungry && broke) {
return false;
}
}
Write your code here:
public boolean willGetTakeout(boolean hungry, boolean broke) { }
Write a method table
that takes an
int
argument n and prints out a
multiplication table from 1 × 1 to n × n. For instance if called
like table(5)
it should print something like:
1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25
What does this method do?
public String mystery(String s) {
String r = "";
for (int i = 0; i < s.length(); i++) {
r = s.substring(i, i + 1) + r;
}
return r;
A prefix of a string is any substring that occurs at the beginning of the string. The shortest prefix is the empty string and the longest prefix is the string itself.
Write a method that takes a single String
argument
and prints out, one per line, all the prefixes of the string.