Welcome to Computer Programming

 

String exercises

 

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 4
 */

public class HW2_StringPractice
{

    public static void testOutputOfStrings (String name)
    {
        // example
        String myDog="Luna";
        System.out.println("My dog is " + myDog);

        //Example of a few methods
        int numOfLetters=name.length();
        System.out.println(myFirstName+" is "+ numOfLetters+" letters long");

        //Now if I wanted to replace all the J's with H's
        String spanishName=name.replace('J','H');
        spanishName=spanishName.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 static 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 static 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 static 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 static 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 static 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.");
    }

    //ALL BELOW EXTRA CREDIT or required for all hotshots:
    //Insert the code for maineh that will replace all r with h's as old time mainehs do.
    public static 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.");
    }

    //Insert the code for piglatin that will take the first letter put it on the end and add 'ay'
    public static 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.");
    }

    //Remove all vowels so peanut would say pnt
    public static void removeVowels(String word)
    {
    }

    //SUPER ADVANCED
    //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 static void firstAPlus(String word)
    {
    }

    /** will take in a phrase and change it to all lower case but the first letter will be caps
     * So if they put in fRankenSTEIN it would be Frankenstein
     */
    public static void fixCapitilization (String phrase)
    {

    }

    /**
     * this method takes in a string and prints
     * out the last letter of the string
     * like if they put in apple as word it would print out
     * The last letter of apple is e
     */
    public static void findLast(String word)
    {

    }

    //Capitalize every other letter in the word, so Frankenstein would become FrAnKeNsTeIn
    public static void capitlizeEveryOther(String word)
    {
    }

}