You are on page 1of 3

MAY ALGORITHM CHALLENGE-2010

/**
*
* @author VIP
*/

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*;

/*
<APPLET CODE="flames" width=500 height=500>
</APPLET>
*/

public class flames extends Applet implements ActionListener{

char ch;
String msg,s,d;
StringBuffer b;
int count,ct,i,j,n,m,cur,len;
TextField st,dt,re;

public void init()


{

Label stl=new Label("Your Name:");


st=new TextField(25);
add(stl);
add(st);

Label dtl=new Label("Partner Name:");


dt=new TextField(25);
add(dtl);
add(dt);

Button go=new Button("MATCHING");


add(go);
re=new TextField(10);
add(re);
go.addActionListener(this);

}
public void actionPerformed(ActionEvent ae)

repaint();

public void paint(Graphics g) {


// TODO code application logic here

// INITIALIZATION

msg=d=s="";
ch=' ';
len=cur=0;
count=n=m=0;

s=st.getText();
d=dt.getText();
n=s.length();
m=d.length();

//ELIMINATING SIMILAR ALPHABET IN BOTH NAMES.

for(i=0;i<n;i++)
{
j=d.indexOf(s.charAt(i));
if(j!=-1)
{
char c=d.charAt(j);
s=s.replaceFirst(""+c,"_");
d=d.replaceFirst(""+c,"_");

} //end of loop

//COUNT TOTAL CHARS

for(i=0;i<n;i++)
if(s.charAt(i)!='_')
count++;
for(i=0;i<m;i++)
if(d.charAt(i)!='_')
count++;

ct=count;

// FLAMES CALCULATION

b=new StringBuffer("FLAMES");

for(i=0;i<5;i++)
{
cur=cur+ct;
len=b.length();
if(cur>len)
while(cur>len)
cur-=len;
cur--;
ch=b.charAt(cur);
b.deleteCharAt(cur); // REMOVE CHECKED CHARS

}//end of loop

ch=b.charAt(0);
if(ch=='F') msg="FRIEND";
if(ch=='L') msg="LOVE";
if(ch=='A') msg="AFFECTION";
if(ch=='M') msg="MARRIAGE";
if(ch=='E') msg="ENEMY";
if(ch=='S') msg="SISTER";

g.drawString(" RELATIONSHIP WAS: "+msg,200,100);


re.setText(msg);

}//END OF PAINT

}// END OF CLASS

You might also like