Java Code for interesting Java Game

Reply

Join Date: Oct 2006
Posts: 9
Reputation: LSPUWILLC is an unknown quantity at this point 
Solved Threads: 0
LSPUWILLC's Avatar
LSPUWILLC LSPUWILLC is offline Offline
Newbie Poster

Java Code for interesting Java Game

 
0
  #1
Jun 14th, 2007
Hello everyone!
The other day as I was surfing the net I came accross this Java Game on this web page:

http://www.bosanci.net/ljubav.php

*It is a foreign language and it is a "Crush Calculator" - It asks you to type in a male name in the first string and a female in the second... Then it calculates the final procentage between those 2 persons...


...Ever since, I have been trying to figure out how it works. I dont get how it converts the letters to numbers and a formula or calculations it does to get a final number in the end??

So if someone has ANY ides PLEASE reply.... It would be much appreciated!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,185
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 482
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java Code for interesting Java Game

 
0
  #2
Jun 14th, 2007
>how it converts the letters to numbers
simply put whole alphabet in array and then read name character by character and check out position of character in array and you getter number (there was also some method to do so but can't remember)

algorithm behind will be something silly for combination of peter+marta I got 15% (2 letters same in the names) and for combination peter+petra it returned it 35% (4 letters same in the names where on repeat twice in first "e") so maybe if you try some arabic or other exotic long names you may get some better score
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: LSPUWILLC is an unknown quantity at this point 
Solved Threads: 0
LSPUWILLC's Avatar
LSPUWILLC LSPUWILLC is offline Offline
Newbie Poster

Re: Java Code for interesting Java Game

 
0
  #3
Jun 15th, 2007
Yea, but I dont get how to write the method... the calculating bit.
How do I tell the computer if there are 2 numbers the same that it should add u the %...
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 121
Reputation: tonakai is an unknown quantity at this point 
Solved Threads: 11
tonakai's Avatar
tonakai tonakai is offline Offline
Junior Poster

Re: Java Code for interesting Java Game

 
0
  #4
Jun 15th, 2007
you can simply write a crush calculator by yourself
  1. int calc(string name1, string name2) {
  2. //you can also put any silly calculation
  3. return 50;
  4. }
you either love her/him or not
Good news, everyone!
aykutsoysal.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: Java Code for interesting Java Game

 
0
  #5
Jun 15th, 2007
So this is a method, which calculates the percentage:
  1. for (int i=0; i<mName.length()-1; i++)
  2. {
  3. for (int j=i+1; j<fName.length()-1;j++)
  4. if (mName.charAt[i] == fName.charAt[j])
  5. ok = true;
  6. if (ok == true)
  7. ++nr;
  8. }
  9. allChars = fName.length() + mName.length();
  10. percentage = (nr*100)/allChars;
Or something like that. You can improve it, and add various calculations. Have fun
Last edited by Chaster; Jun 15th, 2007 at 1:36 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,185
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 482
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java Code for interesting Java Game

 
0
  #6
Jun 15th, 2007
It is even cheaper then that. Shame I didn't think of it last night. You just need to look at page source to see what is there . And this is what you get
  1. <script LANGUAGE="JavaScript">
  2. <!-- This script and many more are available free online at -->
  3. <!-- The JavaScript Source!! http://javascript.internet.com -->
  4.  
  5. <!-- Begin
  6. function calc() {
  7.  
  8. first = document.loveform.name1.value.toUpperCase();
  9. firstlength = document.loveform.name1.value.length;
  10. second = document.loveform.name2.value.toUpperCase();
  11. secondlength = document.loveform.name2.value.length;
  12. var LoveCount=0;
  13.  
  14. for (Count=0; Count < firstlength; Count++) {
  15. letter1=first.substring(Count,Count+1);
  16. if (letter1=='L') LoveCount+=3;
  17. if (letter1=='O') LoveCount+=3;
  18. if (letter1=='V') LoveCount+=2;
  19. if (letter1=='E') LoveCount+=3;
  20. if (letter1=='Y') LoveCount+=3;
  21. if (letter1=='O') LoveCount+=1;
  22. if (letter1=='U') LoveCount+=3;
  23. }
  24.  
  25. for (Count=0; Count < secondlength; Count++) {
  26. letter2=second.substring(Count,Count+1);
  27. if (letter2=='L') LoveCount+=3;
  28. if (letter2=='O') LoveCount+=2;
  29. if (letter2=='V') LoveCount+=2;
  30. if (letter2=='E') LoveCount+=3;
  31. if (letter2=='Y') LoveCount+=3;
  32. if (letter2=='O') LoveCount+=1;
  33. if (letter2=='U') LoveCount+=3;
  34. }
  35.  
  36. amount=0;
  37. if (LoveCount> 0) amount= 5-((firstlength+secondlength)/2)
  38. if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
  39. if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
  40. if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
  41. if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
  42. if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
  43. if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
  44. if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
  45. if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
  46. if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
  47. if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
  48. if (LoveCount>22) amount=110-((firstlength+secondlength)/2)
  49.  
  50. if (firstlength==0 || secondlength==0) amount= "Err";
  51. if (amount < 0) amount= 0;
  52. if (amount >99) amount=99;
  53.  
  54. document.loveform.output.value=amount+"%";
  55. }
  56. // End -->
  57. </script>
So he didn't make it, he just took it from other website
Last edited by peter_budo; Jun 15th, 2007 at 1:44 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 3,241
Reputation: The Dude will become famous soon enough The Dude will become famous soon enough 
Solved Threads: 25
The Dude's Avatar
The Dude The Dude is offline Offline
Nearly a Senior Poster

Re: Java Code for interesting Java Game

 
0
  #7
Jun 16th, 2007
Java does not equal JavaScript. The page you linked is JavaScript and the way they do it is right in plain text in the source
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,185
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 482
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java Code for interesting Java Game

 
0
  #8
Jun 16th, 2007
The Dude you are genius, Iwould not know if you do not tell me so

Originally Posted by LSPUWILLC
I have been trying to figure out how it works. I dont get how it converts the letters to numbers and a formula or calculations it does to get a final number in the end??
and I just provided answer
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 3,241
Reputation: The Dude will become famous soon enough The Dude will become famous soon enough 
Solved Threads: 25
The Dude's Avatar
The Dude The Dude is offline Offline
Nearly a Senior Poster

Re: Java Code for interesting Java Game

 
0
  #9
Jun 17th, 2007
I was referring that to the opening poster on this thread
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC