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.
Write a method that takes a single int
argument and
returns an array of that many int
s where each element
in the array has as its value the index where it occurs.
Write a method that takes an array of ints and returns a count of the number of elements in the array whose value is not zero.
Write a method that takes two arguments, an array of ints and and int, and sets all the elements of the array at positions that are proper multiples of the number given to zero. (Proper multiples are multiples other than 0 and the number itself.) For instance, if the second argument is 2, you should set all the elements in the array at even positions greater than position 2 to zero.
Write a method that takes an array of ints and returns a new array containing only the non-zero values in the argument array.
Write a method that takes an array of ints and an int representing an index into the array. It should return the next non-zero value in the array at an index greater than the one given by the second argument. For instance given the array { 0, 0, 10, 7, 0, 13 } and the starting position 3, it should return 13. If there are no non-zero values after the given starting point, return 0.
For the culmination of this week’s Boot ups, write a method that
takes an
int
argument and makes a table of that size with the
numberTable
method. Then set the element of the table
at index 1 (if there is one) to the value 0. Then, starting with the
first non-zero value in the array, i.e. 2, use
clearMultiples
to clear the multiples of each remaining
non-zero value whose multiples have not been cleared. Finally,
return a new array of the non-zero values left in the array using
the nonZeros
method. This array will contain the primes
below the original argument. Note you should use all the other
methods from this week in this method. (You won’t directly call
countNonZeros
but it should be used because
nonZeros
should have called it.)
This technique for finding primes is called the
Sieve of Eratosthenes. The Wikipedia article suggests an optimization that you could
make via a change to clearMultiples
. If you have time,
try to implement it. It’s described in the paragraph in the Overview
section that starts, “As a refinement”. (Note, that it will cause
some of the tests for clearMultiples
to stop passing;
that’s okay. Or you can write a new method that implements the
optimization and use it instead.)
Array exercises.