|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
New to Java
Ok we basically half to make a program where we have a user type in a letter from the alphabet and if they type a constant it says "you have entered a constant", if you type a vowel it says "you've typed a vowel" etc...
im currently downloading the compile tools etc for my Jcreator so right now i dont know how many errors i have at the moment. Example: Would you like to play the game? Enter Y or y or N or n & press return!: K Please enter y or n, Follow directions thank you! Y Enter a letter from A to Z press return! P You entered a constant! (..........and loop it till they decide to quit!) -Help/Pointers 1. I have 3 errors i belive which i cant figure out wats wrong. 2. I dont know which loop would be best for the alphabet a-z and I have no clue how to loop the alphabet so they can choose any letter, I dont wanna make abunch of if statements so the program deinfes every letter. I think i can loop it. 3. If im right a infinite loop would be best to loop the whole program if they wanna keep typing in letters or whatever. 4.If you have any ideas or tips that can make my program shorter, better, or fancyier I'm all ears. (I will put comments after im done. Thx for any help brought to me if i have any other questions or comments i will post here) Code:
import java.io*
public class Program1
{
public static void main (String[] args)
{
InputStreamReader in = new InputStreamReader (System.in);
BufferedReader keyboard = new BufferedReader (in);
String message = keyboard.readLine();
System.out.println ("Would you like to play the game?, If so Enter y or n and press return! ");
if (message.equalIsIgnoreCase ("y"));
{
System.out.println ("Please enter a letter from A-Z! ");
message = keyboard.readLine();
{
if (message.equalIsIgnoreCase ("a"));
if (message.equalIsIgnoreCase ("e"));
if (message.equalIsIgnoreCase ("i"));
if (message.equalIsIgnoreCase ("o"));
if (message.equalIsIgnoreCase ("u"));
{
System.out.println ("You have entered a vowel, YAY!");
}
}
}
if (message.equalIsIgnoreCase("n"));
{
System.out.println ("Thank you for playing, Have a nice day!");
message = keyboard.readline();
}
}
}
Last edited by MadCowDzz : August 24th, 2006 at 08:18 AM. Reason: added [code] tags |
|
#2
|
||||
|
||||
|
You probably know this by now, but your first line is going to give you an error... =)
You're missing a semicolon on your import statement. Change the block where you're checking for a vowel to: Remove the curly-brace before this block Code:
if ((message.equalIsIgnoreCase ("a") || (message.equalIsIgnoreCase ("e") ||
(message.equalIsIgnoreCase ("i") || (message.equalIsIgnoreCase ("o") ||
(message.equalIsIgnoreCase ("u"))
{
System.out.println ("You have entered a vowel, YAY!");
}
As for adding the looping, give it a try... The best part of programming is the trial-and-error learning =)
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
when i first posted i probaly confused you guys but u guys basically know what program im trying to make but with a few minors errors im having. help would be much apprciated.
Whats in red is where the error is taking place and the comments in greens is what the error is and its the same 3 errors and i cant figure out what the heck is wrong plz help! import java.io.*; public class Program1 { public static void main (String[] args) { InputStreamReader in = new InputStreamReader (System.in); BufferedReader keyboard = new BufferedReader (in); String message = keyboard.readLine(); /*Error: must be caught or declared to be thrown*/ System.out.println ("Would you like to play the game?, If so Enter y or n and press return! "); if (message.equalsIgnoreCase("y")) System.out.println ("Please eneter a letter from A-Z! "); message = keyboard.readLine() /*Error: must be caught or declared to be thrown*/ if ((message.equalIsIgnoreCase ("a") || (message.equalIsIgnoreCase ("e") || (message.equalIsIgnoreCase ("i") || (message.equalIsIgnoreCase ("o") || (message.equalIsIgnoreCase ("u")) { System.out.println ("You have entered a vowel, YAY!"); } else System.out.println ("You have enetred a constant, WOOT!"); if (message.equalsIgnoreCase("n")) System.out.println ("Thank you for playing, Have a nice day!") message = keyboard.readLine(); /*Error: must be caught or declared to be thrown*/ } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > New to Java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|