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 two String arguments and returns
a boolean indicating whether the first String is longer than
the second.
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 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 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.)
This is a sample of methods that compute using Strings (and a
few booleans and numbers) with the methods covered in Chapter 7
and the String + 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.
Quick reference
String s = "Foo";s + s ⟹ "FooFoo"s.substring(0, 1) ⟹ "F"s.length() ⟹ 3s.toUpperCase() ⟹ "FOO"s.toLowerCase() ⟹ "foo"s.indexOf("o") ⟹ 1Pro 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.