package exer16;
import java.util.*;
import javax.swing.JOptionPane;
/**
*
* @author mm08-03
*/
public class Main {
/**
* @param args the command line arguments
*/
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
playGame();
}
public static void playGame()
{
String wantRead;
int want = 0;
wantRead = JOptionPane.showInputDialog("F L A M E S\nMenu\n1-Play\n0-Exit");
want = Integer.parseInt(wantRead);
if(want == 1)
{
gameProp();
}
else
{
JOptionPane.showMessageDialog(null, "Till next time! Thanks :D");
System.exit(0);
}
public static String trim(String sentence)
{
sentence = sentence.toLowerCase();
String newName = "";
char[] nameIs = sentence.toCharArray();
int i;
for(i = 0; i<sentence.length(); i++)
{
if(Character.isLetter(nameIs[i]))
newName += nameIs[i];
}
return newName;
}
public static int compareNames(String name1, String name2)
{
char[] nameOne = name1.toCharArray();
char[] nameTwo = name2.toCharArray();
int i, j, counter = 0;
for(i = 0; i < name1.length(); i++)
{
for(j = 0; j <name2.length(); j++)
{
if(nameOne[i] == nameTwo[j])
{
counter++;
break;
}
}
}
//String output = " "+counter;
//JOptionPane.showMessageDialog(null, output);
return counter;
}
public static void match(int count, String name1, String name2)
{
String output = "";
if(count%6 != 0)
count = count%6;
else
count = 6;
if(count == 1)
output = name1 + " & " + name2 + "\n\nFRIENDS";
else if ( count == 2)
output = name1 + " & " + name2 + "\n\nLOVERS";
else if ( count == 3)
output = name1 + " & " + name2 + "\n\nANGRY";
else if ( count == 4)
output = name1 + " & " + name2 + "\n\nMARRIAGE";
else if ( count == 5)
output = name1 + " & " + name2 + "\n\nENEMIES";
else if ( count == 6)
output = name1 + " & " + name2 + "\n\nSWEETHEARTS";
JOptionPane.showMessageDialog(null, output);
public static void gameProp()
{
String first = JOptionPane.showInputDialog("Please enter full name of person #1: ");
String second = JOptionPane.showInputDialog("Please enter full name of person #2: ");
String new1st = trim(first);
String new2nd = trim(second);
String output = first+"\n"+second;
JOptionPane.showMessageDialog(null, output);
int ctrName = compareNames(new1st, new2nd);
match(ctrName, first, second);
}
}