Google
 
Web freesourcecode.blogspot.com
Subscribe to Free Java Source Code !!!

Thursday, March 09, 2006

The FriendShip Calculator

This site has been moved to http://www.99applications.com
To download code/application click the following link 99applications.com/java_programs and you can also find many c and c plus plus common programs in C & C++ section




Welcome to this great invention of Doctor Friend!

We all know that a name can tell a lot about a person. Names are not randomly chosen: they all have a meaning.
Doctor Friend knew this so he made another great invention just for the lonely you!

Sometimes you'd like to know if a relationship with someone could work out. Therefore Doctor Friend himself designed this great machine for you. With The Friendship Calculator you can calculate the probability of a successful relationship between two people. The Friendship Calculator is an affective way to get an impression of what the chances are on a relationship between two people.

This is just a fun application. Dont take it seriously.

Note: This is a funny logic in this testing if this example has caused any problems, please excuse me its only meant for fun!

Download API & Java Source Code For Friendship Calc here....

/**************************************************************************/
Java Program - Friendship Calculator
Author@ Krishnakanth Soni
Feedback@ sonikrishnakanth@gmail.com

Usage: java Friendship rama sita
/**************************************************************************/

Output Screen

import java.util.*;

class FriendShip
{
private String name1;
private String name2;

public void setFirstName( String name1 ){
this.name1 = name1.toUpperCase();
}

public void setSecondName( String name2 ){
this.name2 = name2.toUpperCase();
}

public void setNames( String name1, String name2 ){
this.name1 = name1.toUpperCase();
this.name2 = name2.toUpperCase();
}

private Vector getCount(){
Vector list = new Vector();
String friendShip = "FRIENDSHIP";
String name1 = this.name1;
String name2 = this.name2;
for( int i=0; i<name1.length(); i++ ){
String temp = name1.charAt(i) + "";

if( list.contains(temp) ){
int indexOfElement = list.indexOf( temp );
int prevCount = Integer.parseInt( list.get(++indexOfElement).toString() );
prevCount++;
String newCount = (prevCount) + "";
list.set( indexOfElement, newCount );
continue;
}

list.add( temp );
list.add( "1" );
}

for( int i=0; i<name2.length(); i++ ){
String temp = name2.charAt(i) + "";

if( list.contains(temp) ){
int indexOfElement = list.indexOf( temp );
int prevCount = Integer.parseInt( list.get(++indexOfElement).toString() );
prevCount++;
String newCount = (prevCount) + "";
list.set( indexOfElement, newCount );
continue;
}

list.add( temp );
list.add( "1" );
}

for( int i=0; i<friendShip.length(); i++ ){
String temp = friendShip.charAt(i) + "";

if( list.contains(temp) ){
int indexOfElement = list.indexOf( temp );
int prevCount = Integer.parseInt( list.get(++indexOfElement).toString() );
prevCount++;
String newCount = (prevCount) + "";
list.set( indexOfElement, newCount );
continue;
}

list.add( temp );
list.add( "1" );
}

Vector result = new Vector();

for( int i=1; i<list.size(); i+=2 ){
result.add( list.get(i) );
}

//System.out.println( result );
return result;
}

public int getFriendShipPer(){
Vector count = getCount();
if( count.size() == 1 ){
String result = count.get(0).toString() + "";
return Integer.parseInt(result);
}

if( count.size() == 2 ){
String result = count.get(0).toString() + count.get(1).toString();
return Integer.parseInt(result);
}

do{
Vector sub = new Vector();
int size = count.size() / 2;
//System.out.println( count.size() / 2 );
for( int i=0; i<size; i++ ){
String newC = ( Integer.parseInt( count.get(i).toString() ) + Integer.parseInt( count.get( count.size() - 1 - i ).toString() ) ) + "";

if( newC.length() == 2 )
{
sub.add( (newC.charAt(0) + "") );
sub.add( (newC.charAt(1) + "") );
}else{
sub.add( newC );
}
}

if( (size*2) != count.size() )
sub.add( count.get(size) );

count = new Vector();
count = sub;
//System.out.println( count );
}while( count.size() != 2 );

String result = count.get(0).toString() + count.get(1).toString();
return Integer.parseInt(result);
}

public int getFriendShipPer( String name1, String name2 ){
String temp1 = this.name1;
String temp2 = this.name2;

setNames( name1, name2 );
int fPercentage = getFriendShipPer();
setNames( temp1, temp2 );

return fPercentage;
}

public String toString(){
String result = "[ Friendship Percentage Between " + this.name1 + " And " + this.name2 + " is " + getFriendShipPer() + "% ]";
return result;
}

public static void main(String[] args)
{
//System.out.println("Hello World!");
FriendShip fs = new FriendShip();
if( args.length == 2 ){
fs.setNames( args[0], args[1] );
System.out.println( "\n" + fs.toString() + "\n" );
System.exit(0);
}else{
System.out.println( "\nUse With Proper usage, Find a sample FREINDSHIP Below\n java FriendShip name1 name2 \n" );
}
fs.setNames( "krishna", "radha" );
System.out.println( "\n" + fs.toString() + "\n" );
}
}

Home..