Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Programming 101 ???(Using basic Java methods to create game)
icon5.gif  Programming 101 ??? [message #753864] Sat, 29 October 2011 16:10 Go to next message
Rich  is currently offline Rich Friend
Messages: 2
Registered: October 2011
Junior Member
for the last two days Ive been trying to make a simple game using Java but I am stuck on one part.

The game is like Hangman:

The user is prompted to enter a phrase (assuming the phrase is all lowercase):

Please enter a phrase using all lowercase characters: this is the end


Using the string "this is the end"

I am trying to convert each character in this string into ?s for a second user to guess while leaving the whitespace (spaces) as whitespace.

???? ?? ??? ???

Please enter a character as a guess:


Ive tried TWO versions of code using if/else & one using a switch and both turns even the whitespace into ?:

	if (!phrase.equals(""))
	{
		for (int i=0; i <= phrase.length(); i++)
		{
			int k=0;
			
			
			if (phrase.charAt(k) >= 'a' && phrase.charAt(k) <= 'z')
			{
				q1 = '?';
				c1 += q1;
			}
			else if (phrase.charAt(k) == ' ')
			{
				q2 = ' ';
				
				c1 += q2;
			}
			++k;
			
		}
		System.out.print("\r" + c1);



~and~
for (int i=1; i <= phrase.length(); i++)
		{
			int k=0;
			
			switch (phrase.charAt(k))
			{
			
			case ' ':;
			q2 = ' ';
			
			c1 += q2;
			break;
				case 'a': case 'b':case 'c':case 'd':case 'e':case 'f':case 'g':case 'h':case 'i':
				case 'j':case 'k':case 'l':case 'm':case 'n':case 'o':case 'p':case 'q':case 'r':case 's':
				case 't':case 'u':case 'v':case 'w':case 'x':case 'y':case 'z':;
			q1 = '?';
			c1 += q1;
			
			break;
			
			}
			k++;
			
		}
		System.out.print("\r" + c1);


Both prints
???????????????
and not
???? ?? ??? ???
?

What am I/Eclipse doing wrong?
Re: Programming 101 ??? [message #753877 is a reply to message #753864] Sat, 29 October 2011 19:23 Go to previous messageGo to next message
Rich  is currently offline Rich Friend
Messages: 2
Registered: October 2011
Junior Member
Over 300 views... in a forum designed for developers, and not one response?!

Could someone please help?

I'm not asking to solve the bigger picture for me, but help me understand what's going wrong.

Thanks, in advance.

Rich
Re: Programming 101 ??? [message #753882 is a reply to message #753877] Sat, 29 October 2011 21:52 Go to previous messageGo to next message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
Hi

> Over 300 views... in a forum designed for developers, and not one
> response?!
> Could someone please help?

Please don't take it personal, but this is almost certainly not an
Eclipse issue but a general Java programming issue. This forum is not
the best place for the latter.

Besides that, response times in the Eclipse forums are usually slower
during the weekend and this weekend a lot of people are traveling to
EclipseCon Europe...

I recommend you learn how to use the Eclipse debugger [1]; or if you
prefer watching videos instead of reading [2]; and then step through
your code to see what's going on.

Another hint for future questions (here or anywhere else): code that
nicely conforms to the "Code Conventions for the Java Programming
Language" [3] is more pleasant to read which drastically increases
your chance for an answer.

[1] http://www.vogella.de/articles/EclipseDebugging/article.html
[2] http://eclipsetutorial.sourceforge.net/debugger.html
[3] http://www.oracle.com/technetwork/java/codeconv-138413.html

HTH
Michael
Re: Programming 101 ??? [message #753933 is a reply to message #753877] Sun, 30 October 2011 18:14 Go to previous message
Wojtek  is currently offline Wojtek Friend
Messages: 47
Registered: August 2011
Member
Rich wrote :
> Over 300 views... in a forum designed for developers, and not one response?!

You might also want to try another newsgroup: comp.lang.java.programmer

--
Wojtek :-)
Previous Topic:what's wrong with my eclipse???
Next Topic:plzzz guys help me!!!
Goto Forum:
  


Current Time: Tue Mar 19 08:10:39 GMT 2024

Powered by FUDForum. Page generated in 0.04357 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top