Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 23rd, 2006, 09:40 PM
ChaNgeD ChaNgeD is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 15 ChaNgeD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 21 m 37 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old August 24th, 2006, 08:24 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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

Reply With Quote
  #3  
Old August 24th, 2006, 08:57 PM
ChaNgeD ChaNgeD is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 15 ChaNgeD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 21 m 37 sec
Reputation Power: 0
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*/
}
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > New to Java


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway