1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.Math.*;
import java.lang.Double.*;
import java.util.*;
public class LoveCalc2
extends MIDlet
implements CommandListener, ItemCommandListener
{
public Display display;
public Command CMD_GO = new Command("Calculer", Command.ITEM, 1);
public Command CMD_EXIT = new Command("Quitter", Command.EXIT, 1);
public Form f1 = new Form("LoveCalc");
public TextField tfnom1 = new TextField("Premier prénom : ","",30,TextField.ANY);
public TextField tfnom2 = new TextField("Deuxième prénom : ","",30,TextField.ANY);
public StringItem bcalc = new StringItem("", "Calculer", Item.BUTTON);
public int Score;
public String nom1;
public String nom2;
public String affnom1;
public String affnom2;
private long Totnom1;
private long Totnom2;
private double Moynom1;
private double Moynom2;
private double var1;
private double var2;
private double cov;
private long long1;
private long long2;
private double jour;
private double mois;
private double uuu;
private double ddd;
private double longsol;
private String scor;
private String solution;
private String obsrevation="";
public void LoveCalc()
{
nom1 = tfnom1.getString().toLowerCase().trim();
affnom1=tfnom1.getString();
nom2 = tfnom2.getString().toLowerCase().trim();
affnom2=tfnom2.getString();
if(nom1.length()>nom2.length())
{
nom2 = nom2 + nom2.substring(0,nom1.length()-nom2.length());
}
else if (nom1.length()<nom2.length())
{
nom1 = nom1 + nom1.substring(0,nom2.length()-nom1.length());
}
byte bytenom1[] = nom1.getBytes();
byte bytenom2[] = nom2.getBytes();
Totnom1=0;
Totnom2=0;
for(int i=0;i<bytenom1.length;i++)
{
Totnom1 += bytenom1[i];
Totnom2 += bytenom2[i];
}
Moynom1 = (Totnom1 / bytenom1.length);
Moynom2 = (Totnom2 / bytenom2.length);
cov=0;
var1=0;
var2=0;
for(int i=0;i<bytenom1.length;i++)
{
cov += (bytenom1[i]-Moynom1)*(bytenom2[i]-Moynom2)/bytenom1.length;
var1 += (bytenom1[i]-Moynom1)*(bytenom1[i]-Moynom1)/bytenom1.length;
var2 += (bytenom2[i]-Moynom2)*(bytenom2[i]-Moynom2)/bytenom2.length;
}
Score=(int)(Math.max(cov/(Math.sqrt(var1)*Math.sqrt(var2))*100,-1*cov/(Math.sqrt(var1)*Math.sqrt(var2))*100));
Alerte("Résultats",affnom1+" + "+affnom2+" = "+Score+"%");
}
private void Alerte(String titre,String a)
{
Alert avert = new Alert(titre, a, null, AlertType.INFO);
display.setCurrent(avert);
}
public int nombrer(char n)
{
if (n=='a') return 1;
if (n=='b') return 2;
if (n=='c') return 3;
if (n=='d') return 4;
if (n=='e') return 5;
if (n=='f') return 6;
if (n=='g') return 7;
if (n=='h') return 8;
if (n=='i') return 9;
if (n=='j') return 10;
if (n=='k') return 11;
if (n=='l') return 12;
if (n=='m') return 13;
if (n=='n') return 14;
if (n=='o') return 15;
if (n=='p') return 16;
if (n=='q') return 17;
if (n=='r') return 18;
if (n=='s') return 19;
if (n=='t') return 20;
if (n=='u') return 21;
if (n=='v') return 22;
if (n=='w') return 23;
if (n=='x') return 24;
if (n=='y') return 25;
if (n=='z') return 26;
if (n==' ') return 0;
else return 0;
}
public void LoveCalcJour()
{
nom1=tfnom1.getString().toLowerCase().trim();
affnom1=tfnom1.getString();
nom2=tfnom2.getString().toLowerCase().trim();
affnom2=tfnom2.getString();
long1 = nom1.length() + 3;
long2 = nom2.length() + 3;
uuu=0;
ddd=0;
for (int i=0;i<(long1-3);i++)
{
uuu += nombrer(nom1.charAt(i));
}
for (int j=0;j<(long2-3);j++)
{
ddd += nombrer(nom2.charAt(j));
}
jour = Calendar.DAY_OF_MONTH;
mois = Calendar.MONTH;
if ((long1==3 && long2==3) || (uuu==0 || ddd==0))
{
Score = 0;
obsrevation = "Vous n'aimez pas les scènes de ménages ?? Evitez votre moitié !!!";
}
else
{
solution = (1/(140*(long1*long2+long2*long1+uuu+ddd)*(jour+1)*(mois+1)*(jour+1)*(mois+1)))+" ";
longsol = solution.length();
int Score1 = Character.digit(solution.charAt((int)(longsol-10)), 10);
int Score2 = Character.digit(solution.charAt((int)(longsol-7)), 10);
Score=Score1*10+Score2;
if (Score > 0) { obsrevation="Vous n'aimez pas les scènes de ménages ?? Evitez votre moitié !!!";}
if (Score > 4) { obsrevation="Si vous êtes rentré(e) tard hier soir, faites-vous pardonner !";}
if (Score > 10) { obsrevation="Réfléchissez bien : n'avez vous pas oublié son anniversaire, sa fête, ou autre chose ?";}
if (Score > 20) { obsrevation="L'amour fou, c'est pas pour aujourd'hui, retentez votre chance demain.";}
if (Score > 40) { obsrevation="Journée sans nuage, mais sans grand soleil non plus. Vous l'aimez ? Offrez lui des fleurs";}
if (Score == 51) { obsrevation="51 ? Tiens donc... Les soirées trop arrosées, vous aimez ça ? Pas votre dulciné(e) apparemment, alors 2 aspirines et au lit !";}
if (Score > 51) { obsrevation="Belle journée sur votre couple, mais ne comptez pas sur une grande déclaration d'amour de la part de votre amour.";}
if (Score == 69) { obsrevation="69 ? Et bien... Envie d'un calin olé olé? C'est le moment de vous dépenser sans compter.";}
if (Score > 69) { obsrevation="Un conseil pour terminer cette belle journée comme vous l'avez commencée : dîner romantique et ballade en amoureux.";}
if (Score > 80) { obsrevation="Vous l'aimez passionnément ? Lui (ou elle) aussi, alors si vous ne l'avez pas encore fait, c'est le jour ou jamais de lui avouer.";}
if (Score > 90) { obsrevation="Si vous ne l'avez pas encore demandé(e) en mariage, respirez profondément et jetez-vous à l'eau, c'est le moment.";}
}
Alerte("Résultats",affnom1+" + "+affnom2+" : "+Score+"%"+" --> "+obsrevation);
}
public void startApp()
{
display = Display.getDisplay(this);
bcalc.setDefaultCommand(CMD_GO);
bcalc.setItemCommandListener(this);
f1.append(tfnom1);
f1.append(tfnom2);
f1.append(bcalc);
f1.addCommand(CMD_EXIT);
f1.setCommandListener(this);
display.setCurrent(f1);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Item item)
{
if (c == CMD_GO)
{
LoveCalcJour();
}
}
public void commandAction(Command c, Displayable d)
{
destroyApp(false);
notifyDestroyed();
}
} |
Partager