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 String
argument and
returns a String
consisting of just the first character
of the argument.
Write a method that takes a single String
argument and
returns a String
consisting of just the last character
of the argument.
Write a method named pair
that takes two
String
arguments and returns a single
String
consisting of the two arguments separated by the
word and
.
Write a method that takes two String
arguments and
returns a boolean
indicating whether the first
String
is longer than the second.
Write a method named upDown
that takes a single
String
argument and returns a
String
consisting of the original
String
all in upper case concatenated (“smooshed
together”) with the String
all in lower case.
Write a method named contains
that takes a two
String
arguments and returns true
if the
second String
is contained in the first and false if it
is not.
Write a method named slug
that takes three
String
arguments and returns a “slug” consisting of the
three String
s joined together with hyphens and all in
lower case. For instance
slug("Foo", "Bar", "BAZ")
would return
"foo-bar-baz"
.
Write a method named simplePigLatin
that takes two
arguments, a String
containing a single word and a
number indicating the index of the first vowel in the word, and
returns the word translated into Pig Latin.
Write a method that takes a single String
argument and
returns a String
consisting of the argument in
capitalized form, i.e. with the first letter in uppercase and the
rest of the letters in lower case.
Write a method that takes a two arguments, a String
and
an int
and returns a String
consisting of
the character in the first argument at the index given by the
second.
Write a method that takes a single String
argument and
returns the first half of the String
. (If the
String
has an odd number of characters it doesn’t
matter whether or not you include the extra character.) For instance
the first half of "foobar"
is "foo"
but if
the argument was "fooquux"
then either
"foo"
or "fooq"
would be acceptable return
values.
Write a method that takes a single String
argument and
returns the second half of the String
. (If the
String
has an odd number of characters it doesn’t
matter whether or not you include the extra character.) For instance
the second half of "foobar"
is "bar"
but
if the argument was "fooquux"
then either
"quux"
or "uux"
would be acceptable return
values. For maximum style points write this method and
firstHalf
so that
firstHalf(s) + lastHalf(s)
gives you back
s
.
Write a method that takes a two String
arguments and
returns a String
consisting of the characters of the
first argument up to but not including the first occurrance of the
second argument in in the first. You can assume the first
String
contains the second somewhere.
Write a method that takes a single String
argument
which will consist of a full name in the form a first name, a space,
and a last name and returns a String
containing just
the first name.
Write a method that takes a single String
argument
which will consist of a full name in the form a first name, a space,
and a last name and returns a String
containing just
the last name.
Write a method that takes two String
arguments and
returns true if, and only if, the first argument starts with the
second argument.
Write a method that takes two String
arguments and
returns true if, and only if, the first argument ends with the
second argument. You can assume the first argument is longer than
the second.
Write a method that takes a single String
argument and
returns a String
consisting of the the middle 50% of
the argument, i.e. the original String
with the first
and last quarter removed.
Write a method that takes a single String
argument and
returns a String
consisting of two characters, the
uppercase version of the last character of the argument
String
and the lowercase version of that same
character.
Write a method that takes a two arguments, a String
and
an int
and returns a two-character String
consisting of the character in the first argument at the index given
by the second, once in upper case and then in lower case.
Write a method that takes a single String
argument that
will be at least two-characters long and returns a two-character
String
consisting of just the first and last characters
of the String
.
Write a method that takes a single String
argument and
returns a String
consisting of the second half of the
original String
followed by the first half. If the
String
is an odd number of characters it doesn’t matter
whether the extra character goes with the front or the back.
Write a method that takes a single String
consisting of
a first and last name separated by a space and returns a
String
with the first and last name separated by a
space but each capitalized.
Write a method that takes a single String
argument
which will consist of a full name in the form a first name, a space,
and a last name and returns a String
containing the
person’s initials, i.e. the first letter of their first name
followed by the first letter of their last name.
This is a test of writing methods that compute using
String
s (and a few booleans
and numbers)
with the methods covered in Unit 2 and the +
operator.
As is usually the case when writing methods, you should be on the
lookout for opportunities to implement methods in terms of other
methods you’ve already written, especially in the later problems.
The questions are roughly arranged from easier to harder and the later ones are worth more. So if you get stuck on an early question, probably best to move on and come back to it.
Quick reference
String s = "Foo";
s + s ⟹ "FooFoo"
s.substring(0, 1) ⟹ "F"
s.length() ⟹ 3
s.toUpperCase() ⟹ "FOO"
s.toLowerCase() ⟹ "foo"
s.indexOf("o") ⟹ 1
Pro tip: when you click one of the method buttons, the name of the method is copied to your clipboard so you can paste it into your code, saving typing and avoiding spelling errors. Finally, click the black triangle at the start of these instructions to collapse them and have more room to code.