Alex,
If you are truly this lost already, then you must have missed class, lectures, or have not read the required material. dcminter gave you a very good link to get you started, but if you are not willing to help yourself understand, then neither are we. Deadline or not, you still have to learn the very basics before it will make any sense and that is something we cannot do for you.
Les
What is this "Keyboard" class?
It's some non-standard IO stuff. I'm not sure where it originates, but it seems to be used in lots of "introduction to Java" type university courses. Many of the homework questions mention it.
It may be [url http://duke.csc.villanova.edu/jss/keyboard.html]this one[/url].
public class LetterCounter extends Thread
{
public void run()
{
String sentence = (Keyboard.readString()).toUpperCase();
int spaceCnt = 0, vowelCnt = 0, conCnt = 0;
for(int i=0;i< sentence.length();i++)
{
char c = sentence.charAt(i);
int n = Character.getNumericValue(c);
if (Character.isLetter(c))
{
if (n == 10 || n == 14 || n == 18 || n == 24 || n == 30)
vowelCnt++;
else
conCnt++;
}else if(Character.isWhitespace(c))
spaceCnt++;
}
System.out.println("Vowels: " + vowelCnt + "\nConsonants: " + conCnt + "\nSpaces: " + spaceCnt);
}
public static void main(String [] args)//starting point for Java progras
{
Thread t = new LetterCounter();
t.start();
}
}
Let me know how it works out.
Don't be so critical. People learn from examples and that's what Billy is trying to provide here. I mean sure, he could just copy that code and turn it in without looking at it, and sure, the professor wouldn't suspect a thing since it is *obviously * using only basic Java features. ..
I think that AlexGM16 would do well to take this code and turn it in as is. He's obviously frustrated by his Java experience. We wouldn't want him to get discouraged!
thanks billy...and no i didnt copy the code because i also have to look for commas, but i just wanted to learn how to approach it. I learned a lot more by looking at this example, asking myself what this line of code meant, looked it up, and continued. I think learning by example is a great way to approach programming. Plus my programming teacher has to teach a business systems and tech class, programming 1 and 2 at the same time while she is teaching me (programming ap)
thanks a lot billy
o yeah and keyboard class is sort of a classroom package (cs1 package i believe) that hides a lot of the I/O method stuff to make it easy for you to get data from a client.
Message was edited by:
AlexGM16
aha i get it! Using the for loop it gets the values for every character entered in the string. Then it does an if statement to check it its a vowel, otherwise its a consonant. Then the isWhitespace counts for spaces.
One question where do i go to find the list of values for each string entered by a keyboard?
> One question where do i go to find the list of values for each string entered by a keyboard?
If you're using the Keyboard class (download zip file from http://duke.csc.villanova.edu/jss/keyboard.html),
you can use its readWord() method.
If you have Java 5.0, the Scanner class has useDelimeter() and next() methods.
> One question where do i go to find the list of values
> for each string entered by a keyboard?
Not sure I understand you correctly but your Keyboard class has a method to read and return a String that was type in. You then pass that String to your method that loops over the String and counts the consonants, vowels, spaces etc.