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 public class named Numbers
. This class is going
to represent an expandable list of numbers with methods for
accessing individual numbers and also for getting information about
the whole list, such as the average of all the numbers.
Add two instance variables, an int[]
called
numbers
and an int
called
size
. They should be—as most instance variables
are—private
. The array numbers
will be
used to hold the numbers added to this object. And
size
will always be the number of numbers that have
been added to the object.
Write a constructor that takes an int
argument and
initializes the instance variable numbers
to be an
array of that size. (Note that size
will automatically
be initialized to 0
as the default
int
value which is perfect because the size of a
Numbers
before any numbers have been added is indeed
zero.)
Write a method size
that takes no arguments and returns
the value of size
.
Write a method add
that takes an
int
argument and adds the value to the array of
numbers, using size
as the index. It should then
increment size
so the next number will be added at the
next position of the array.
Modify the add
method so if it is called when the array
is full (i.e. size
is equal to the length of the array)
it makes a new array twice the size of the old array, copies the
elements from the old array into it, and then adds the new number.
Write a method get
that takes a single
int
argument and returns the element at that index of
the numbers
but only if the argument is less than
size
. If it is negative or greater or equals than
size
you should execute the statement:
throw new IndexOutOfBoundsException(i)
where
i
is the argument. (This is a feature of Java that is not part of the
AP curriculum but I’ll explain it briefly in class.)
Write a method removeLast
that “removes” the last
element in the list by decrementing size
so that future
attemps to access it via get
will fail. Return the
number that was “removed”. If size
is zero, you should
execute the statement
throw new IndexOutOfBoundsException()
.