Hello everyone!
The other day as I was surfing the net I came accross this Java Game on this web page:

*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!

## All 8 Replies

>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

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 %...

you can simply write a crush calculator by yourself

``````int calc(string name1, string name2) {
//you can also put any silly calculation
return 50;
}``````

you either love her/him or not :)

So this is a method, which calculates the percentage:

``````for (int i=0; i<mName.length()-1; i++)
{
for (int j=i+1; j<fName.length()-1;j++)
if (mName.charAt[i] == fName.charAt[j])
ok = true;
if (ok == true)
++nr;
}
allChars = fName.length() + mName.length();
percentage = (nr*100)/allChars;``````

Or something like that. You can improve it, and add various calculations. Have fun :P

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:D . And this is what you get

``````<script LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function calc() {

first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {
letter1=first.substring(Count,Count+1);
if (letter1=='L') LoveCount+=3;
if (letter1=='O') LoveCount+=3;
if (letter1=='V') LoveCount+=2;
if (letter1=='E') LoveCount+=3;
if (letter1=='Y') LoveCount+=3;
if (letter1=='O') LoveCount+=1;
if (letter1=='U') LoveCount+=3;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='L') LoveCount+=3;
if (letter2=='O') LoveCount+=2;
if (letter2=='V') LoveCount+=2;
if (letter2=='E') LoveCount+=3;
if (letter2=='Y') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3;
}

amount=0;
if (LoveCount> 0) amount=  5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)

if (firstlength==0 || secondlength==0) amount= "Err";
if (amount < 0) amount= 0;
if (amount >99) amount=99;

document.loveform.output.value=amount+"%";
}
//  End -->
</script>``````

So he didn't make it, he just took it from other website ;)

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 :)

The Dude you are genius, Iwould not know if you do not tell me so :D

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??