|
String exercises
Work in groups and try to make the following methods. Submit online. Email me questions or come at 7:20 on Tuesday (Monday's a holiday).
Start in Bluej by creating a new class (naming it anything) and pasting the contents below in it.
/**
* This is the shell of code to practice with strings
*
* @author J. Borland
* @version October 7, 2011
*/
public class MorePracticeWithVariables
{
public void testOutputOfStrings ()
{
// example
String myFirstName="Jeff";
System.out.println(myFirstName);
//Example of a few methods
int numOfLetters=myFirstName.length();
System.out.println(myFirstName+" is "+ numOfLetters+" letters long");
//Now if I wanted to replace all the J's with H's
String spanishName=myFirstName.replace('J','H');
System.out.println("Your Spanish name is"+ spanishName);
}
//Insert the code for instult user that will take in a name and insult them viciously
//Like Jeff is a turtle
public void insultUser(String name)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
//Insert the code to compliment user as described below
//If they said Jeff, it would say Jeff, Jeff, say it twice its just as nice
public void complimentUser(String name)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be a dded.");
}
//Insert the code to say name and player number like "Jeff Borland is player number 14"
public void sportIdentifier(String name, int number)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
//Insert the code to say name and team like "Jeff Borland plays for the Bears"
public void sportsTeam(String name, String team)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
//Insert the code that will say how many letters are in total in both words
//So if they put in apple and then sauce it would say 10.
public void findLengthTotal(String word1, String word2)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
//Insert the code for maineh that will replace all r with h's as old time mainehs do.
public void makeMaineh(String phrase)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
//EXTRA CREDIT - ALL AP MUST TRY:
//Insert the code for piglatin that will take the first letter put it on the end and add 'ay'
public void makePigLatin(String word)
{
//the following line is just so the user understands that program is not finished. Replace this with your code.
System.out.println("The code for this method needs to be added.");
}
}
Hot shots (you know who you are) must do the following.
Add the code below:
//Remove all vowels so peanut would say pnt
public void removeVowels(String word)
{
}
//The method would find from the first A to the end
// So if the word was Trash it would say ash
// Or the word Lousiana would be ana
public void firstAPlus(String word)
{
}
|