|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD |
Object
StringStuff
Utility class for Strings.
Implement each method. Whenever you write a method, write a small
driver (main() method) to test it and make sure that it works.
You should also show it to me at that point.
Method Summary | |
static String |
acronym(String str)
Creates an acronym out of a string. |
static char |
chosenLetter(String choices)
Gets the user's choice of a letter. |
static int |
countLetter(String str,
char letter) Counts how many occurences of a certain letter are in a given String. |
static String |
firstWordOf(String str)
Returns the first word of a string |
static String |
FLToLF(String name)
Converts a name from first name last name format to last name, first name format. |
static boolean |
inOrder(String str1,
String str2) Determines whether two strings are in lexicographical order. |
static String |
LFToFL(String name)
Converts a name from last name, first name format to first name last name format. |
static void |
printWords(String str)
Prints all of the words in a String on seperate lines. |
static String |
reverseString(String str)
Reverses the order of the letters in a string |
static String |
rotateOne(String str)
Takes a string and shifts every letter one position to the left, moving the first letter to the end. |
static void |
scrollMessage(String str)
Prints a string like a rotating banner. |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify,
notifyAll, toString, wait, wait, wait |
Method Detail |
public static String rotateOne(String str)
Example: If the input is "Rotate Me " the return value will be "otate Me R"
str
- the string to rotate public static void scrollMessage(String str)
Example: If the input is "Rotate Me" the output will look like:
Rotate Me...and so on.
otate Me R
tate Me Ro
ate Me Rot
te Me Rota
e Me Rotat
Me Rotate
Me Rotate
e Rotate M
Rotate Me
Rotate Me
str
- the text for the rotating bannerpublic static String reverseString(String str)
str
- the string to reverse public static String firstWordOf(String str)
str
- the string to find a word in public static char chosenLetter(String choices)
Sample run (with input parameter of "ABC"):
Choose
one of the following letters:
A, B, C
Your choice? Z
Invalid choice. Your choice? B
'B' is returned.
choices
- a String containing characters that
represent valid letter choices public static int countLetter(String str,
char letter)
Example: If the inputs are "occurences" and 'c' it will return 3
str
- the string to searchletter
- the letter to search for public static void printWords(String str)
Example: If the input is "java programming is fun" the output
will be:
java
programming
is
fun
str
- a String containing words seperated by
spacespublic static String acronym(String str)
Example: If the input is "Sun Microsystems, Incorporated" the return value will be "SMI"
str
- the String to make an acronym of public static String FLToLF(String name)
Example: If the input is "John Doe" the return value will be "Doe, John"
name
- the name, with the first name before the
last name, with a space between them. The first name may contain a
space, the last name may not. public static String LFToFL(String name)
Example: If the input is "Doe, John" the return value will be "John Doe"
name
- the name, with the last name followed by
a comma, a space, and the first name. public static boolean inOrder(String str1,
String str2)
str1
- the first stringstr2
- the second string
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD |