Wednesday, January 11, 2017

Java Program : How to find the relation between a boy and a girl using FLAMES.

It is really a fun game. Below find out Java code for this game.


You can check LOVE Calculator  .


Here is program.


package swain.swain;

public class Flames {

public static String getMatchResult(String fname, String sname) {
String firstName, secondName;
if (fname != null & sname != null) {
firstName = fname.trim().toLowerCase();
secondName = sname.trim().toLowerCase();
String firstNames[] = firstName.split(" ");
String secondNames[] = secondName.split(" ");
firstName = "";
secondName = "";
for (int i = 0; i < firstNames.length; i++) {
firstName = firstName + firstNames[i];
}
for (int i = 0; i < secondNames.length; i++) {
secondName = secondName + secondNames[i];
}
int length = secondName.length() + secondName.length();
boolean namecheck[] = new boolean[secondName.length()];
for (int i = 0; i < secondName.length(); i++) {
namecheck[i] = false;
}
for (int i = 0; i < firstName.length(); i++) {
for (int j = 0; j < secondName.length(); j++) {
if ((namecheck[j] == false) && (firstName.charAt(i) == secondName.charAt(j))) {
namecheck[j] = true;
length = length - 2;
break;
}
}
}
boolean flamescheck[] = new boolean[6];
for (int i = 0; i < 6; i++) {
flamescheck[i] = true;
}
int count = 6;
int k = 1, deleted_letters = 0;
int j;
for (j = 0; j <= count; j++) {
if (k <= length) {
if (j == count) {
j = 0;
}
if (flamescheck[j] == true) {
k = k + 1;
}
}
if ((k - 1) == length) {
deleted_letters = deleted_letters + 1;
flamescheck[j] = false;
k = 1;
}
if (deleted_letters == 6) {
if (j == 0) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " are good FRIENDS";
} else if (j == 1) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " are LOVERS";
} else if (j == 2) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " have alot of AFFECTION";
} else if (j == 3) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " are MARRIED";
} else if (j == 4) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " are ENEMIES";
} else if (j == 5) {
return firstName.toUpperCase() + " and " + secondName.toUpperCase() + " are SIBLINGS";
}
break;
}
}
}
return null;
}

public static void main(String args[]) {
System.out.println(Flames.getMatchResult("Rama", "Sita"));
}
}

Output:

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...