Thursday, October 12, 2017

Fun Game : FLAMES Calculator.

In School time every one had tried out this game seriously/secretly with your dream one name. So we all know the rules of the game right?!.

 Lets look it into coding,

Here i have done the coding for this fun game,


/**
* Do flames check.Here we are finding the number of unmatched characters in both name.
*
* @param p_sYourName the p s your name
* @param p_sPartnerName the p s partner name
*/
private static void doFlamesCheck(String p_sYourName, String p_sPartnerName) {
int l_iUnLength = p_sYourName.length();
int l_iPnLength = p_sPartnerName.length();
for (int i = 0; i < p_sYourName.length(); i++) {
Loop: for (int j = 0; j < p_sPartnerName.length(); j++) {
if (p_sYourName.charAt(i) == p_sPartnerName.charAt(j)) {
l_iUnLength--;
l_iPnLength--;
break Loop;
}
}
}

int count = l_iUnLength + l_iPnLength;
doFlames(count);
}


/**
* Do flames.Here we find the character for the flame.
*
* @param val the val
*/
private static void doFlames(int val) {
String l = "FLAMES";
while (l.length() > 1) {
int k = val % l.length();
if (k != 0) {
l = l.substring(k, l.length()) + l.substring(0, k - 1);
}
if (k == 0) {
l = l.substring(0, l.length() - 1);
}

}
findRelation(l.charAt(0));
}


/**
* Find relation. Here just to print the relationship between both depends on doFlames() return char.
*
* @param rel the rel
*/
private static void findRelation(char rel) {
switch (rel) {
case 'F':
System.out.println("friendship");
break;
case 'L':
System.out.println("Love");
break;
case 'A':
System.out.println("Affection");
break;
case 'M':
System.out.println("Marriage");
break;
case 'E':
System.out.println("Enemy");
break;
case 'S':
System.out.println("Sister");
break;

default:
System.out.println("--");
break;
}
}

       /**
* The main method. Get the input from user to find the flames relationship.
*
* @param args the arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Your Name : ");
String l_sYourName = input.next();
System.out.println("Enter Your Partner Name : ");
String l_sPartnerName = input.next();
doFlamesCheck(l_sYourName, l_sPartnerName);
}

NOTE: Please share your comments to improve the blog. Thank you.!