So I have a method that creates an array of 100 randomly generated characters.
Here it is:
//method to generate random character between ch1 and ch2
public static char getRandomCharacter(char ch1, char ch2)
{
return (char) (ch1 + Math.random() * (ch2 -ch1 +1));
}
//==========================================
//method to assign generated characters (between a and z) to a 100 character array
public static char[] createArray()
{
//declare a 100 character array
char[] character = new char[100];
//for loop assigning the random characters to the array using getRandomCharacter method
for (int x = 0; x < character.length; x++)
character[x] = getRandomCharacter('a', 'z');
//for loop outputting the characters in the array
for (int x = 0; x < character.length; x++)
System.out.println(character[x]);
return character;
}
Now I need to create a method that takes the 100 generated characters, and counts how many times each vowel was generated. I am stuck with this one.
This is what I have so far:
public static void countArray()
{
int vowelA, vowelE, vowelI, vowelO, vowelU, vowelY;
int elsePlaceHolder = 0;
for (int x = 0; x < 100; x++)
{
if ((createArray()) == ('a'))
vowelA++;
else if ((createArray()) == ('e'))
vowelE++;
else if ((createArray()) == ('i'))
vowelI++;
else if ((createArray()) == ('o'))
vowelO++;
else if ((createArray()) == ('u'))
vowelU++;
else if ((createArray()) == ('y'))
vowelY++;
else
elsePlaceHolder++;
}
I believe I am correct with using a for loop to do this, but I don't think I'm executing it correctly. Once that executes I can display the amount of times the vowels were counted by using the int variables. That elsePlaceHolder variable is there because I did not know what to do with the else statement.
Can anyone point me in the right direction with my countArray() method? It would be much appreciated!