|
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="t="1.Jeff Borland,2.Chad Buzzell,3.TJ Grey";
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. 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
------------- ------
Jeff Borland 3
Chad Buzzell 2
TJ Grey 1
============= ======
Total (3 names) 6
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 StringTest
{
String list="1.Jeff Borland,2.Chad Buzzell,3.TJ Grey";
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
}
//main method for Eclipse
public static void main(String[] args)
{
StringTest s=new StringTest();
s.findName(3);
}
}
|