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 Strings 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. (Note,
there is actually a startsWith method on
the String class but the tests fail if you use it here.)
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 using Strings along with a
few booleans and numbers using the method you learned about in
Chapter 7 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. You may use
the AP CSA quick reference but otherwise this is a closed book
test.