1 program needed
Write an application to :
1.create a LinkedList called wordList
2.Input a sentence(several words) into the list.
3.count and display the total words in the list
4.count the number of words that begins with vowel and consonants in the list and display them
according to the following format:
Words begin with vowels Count
A or a ..............x
E or e ..............x
I or i ...............x
O or o .............x
U or u ..............x
Words begin with consonants x
CODE
import java.util.*;
import javax.swing.*;
public class Lab5
{
public static void main(String args[])
{
//Q.1 Create a LinkedList called wordList
LinkedList wordList= new LinkedList();
String str,word; //declare the variable
int count=0;
int vowels=5;
int consonants=26;
//Q.2 Input a sentence(several words)into the list
str = JOptionPane.showInputDialog("Enter a word : "); {
wordList.addFirst(str);
}
//Q.3 Count and display the total words in the list
//int count=0;
for(int k=0;k<wordList.size();k++)
{
System.out.println(wordList.get(k));
count++;
count = wordList.size();
}
//Q.4 Count to the number of words that begins with vowel
//and consonants in the list and display
for (int i = 0; i < wordList.size(); i++) {
String next = (String) wordList.get(i);
switch (next.charAt(0)) {
case 'a': case 'A':
vowels++;
break;
case 'e': case 'E':
vowels++;
break;
case 'i': case 'I':
vowels++;
break;
case 'o': case 'O':
vowels++;
break;
case 'u': case 'U':
vowels++;
break;
default:
consonants++;
System.out.println("words begin with vowels count");
}
}
}
}
theres no syntax error,but the output damn sucks.come on help me on this last minute!