notes intro/old submit AP Problems the dump links

String Lab Activity


This is a short activity just to practice some stuff with Strings.

Start with a class called StringTest and in it have a global string called:

String list="1.Evelyn Randazzo,2.Zhane Cariglia,3.Cade Violette";


Create the following methods:

1. public String findName(int number)

2. public String findFirstName (int number) - you will need to findName and get the whole name and then return the portion of the string from the beginning until the space.

3. public void replaceName(int number, String name) - find the name at the number and use replace to switch it with the new name.

4. public int findLengthName(int number) - find the length of the whole name and returns that

5. Extra public int findNumberOfVowels(int number) - finds the number of vowels in the word; this is tricky you will need to search through each letter and see if its a vowel. you could use a loop like: for (int i=0; i<

6. Extra credit: public void printList() - to print a list of names with vowel count like below:

==   Student Names    ==
Name            Vowels
-------------   ------
Evelyn Randazzo   5
Zhane Cariglia    6
Cade Violette     6
=============   ======
Total (3 names)   17


Start with this code if you want:

 * A Class to Practice with Strings.
 * @author (your name)
 * @version (a version number or a date)
public class StringActivity2
    String list="1.Evelyn Randazzo,2.Zhane Cariglia,3.Cade Violette";
    public String findName(int number)
        return ""; //replace with your code
    public String findFirstName (int number)
        String fullName=findName(number);
        return "working on it";
    public void replaceName(int number, String name)
        //replace with your code
    public int findLengthName(int number)
        return 0; //replace with your code
    public int findNumberOfVowels(int number)
        return 0;//replace with your code
    public void printList()
        //replace with your code

    String colorList="ea1717,3017ea,17ea1a,eab217,ea17e7,17eaca,228e53,8e226e,e56e00,7c1717,8d9e22,3dffa4,e06650,4ca37d,0f3022";
    //Extra credit - This method will find a random color (from list and then remove it from the list, so it cant be chosen again).
    public String findRandomColor(){
    	return null;

    //main method for Eclipse
    public static void main(String[] args)
        StringActivity2 s=new StringActivity2();
        System.out.println("Full name is " + s.findName(3));
        System.out.println("First name is " + s.findFirstName(3));
        s.replaceName(1, "Jacob Goldberg");
        System.out.println("Now the name is " + s.findLengthName(1) + " letters long.");        
        System.out.println("Number of vowels in word 3 is " + s.findNumberOfVowels(3));