RSS Forums RSS

Scramble using JSP

Please support our JSP advertiser: Programming Forums
Reply
Posts: 5
Reputation: zoroman is an unknown quantity at this point 
Solved Threads: 0
zoroman zoroman is offline Offline
Newbie Poster

Scramble using JSP

  #1  
Nov 29th, 2008
Hi. I need to do a scramble game.
Simply I need to randomly select a word from my set of strings and print out in shuffled string. Such as if the word is "banana" it should print out something like "anaban" and there should be text field for user to enter and guess the correct word. I also need to keep record correct and wrong number of guesses.
I am quite new to the jsp and couldnt go much further. Please help =(

I have included my jsp file in zip.
Attached Files
File Type: zip scramble.zip (1.5 KB, 2 views)
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,144
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 121
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Scramble using JSP

  #2  
Nov 30th, 2008
JSPs should only be used for display purposes in Web Applications, kind off like swing and AWT are used for the User Interface. Your actual programming logic should be written in normal Java class, to the methods of which you will pass your parameters (in this case the word to be scrambled) and they will return back the result. So never put your programing logic inside a JSP.
For this small assignment of your you may think the above advice is an overkill but its always better to start using the right approach as early as possible.
By checking out your code I suggest you use consistent indentation. There are some places where you have indented correctly whereas at other places you have just conveniently just forgotten about it. You can read here about the code conventions recommended by Sun while programming in Java.

Also look at the following piece of code:-
  1. if (guessed == target){

target and guessed are both String objects. The == operator for in case references to objects checks if target and guessed both point to the same String object. So guessed == target would evaluate to true only in the following case : -
  1. target = new String("jack");
  2. guessed = target;
  3. if (guessed == target){

But you need to check if the contents of the two strings target and guessed are the same. So for that you need to use the equals() method of the String class (or equalsIgnoreCase() if you do not wish to consider the case), So the above statement should then be :-

  1. if (guessed.equalsIgnoreCase(target)){

There might be a few more problems in your JSP but I suggest you at least implement what has been mentioned here for a start.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote  
Posts: 5
Reputation: zoroman is an unknown quantity at this point 
Solved Threads: 0
zoroman zoroman is offline Offline
Newbie Poster

Re: Scramble using JSP

  #3  
Dec 5th, 2008
Thank you, I have sorted out
Reply With Quote  
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Scramble using JSP

  #4  
Dec 6th, 2008
Would you mind to share your solution?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the JSP Forum
Views: 750 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:09 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC