diff --git a/src/main/java/fr/myny/stats/Statistics.java b/src/main/java/fr/myny/stats/Statistics.java index 166abc2..805b2ea 100644 --- a/src/main/java/fr/myny/stats/Statistics.java +++ b/src/main/java/fr/myny/stats/Statistics.java @@ -8,7 +8,7 @@ import java.sql.SQLException; import java.sql.Statement; /** - * Classe permettant de renvoyer les statistiques + * Classe permettant de renvoyer les statistiques a partir de la DB */ public class Statistics { public DataBase maDB; @@ -34,39 +34,40 @@ public class Statistics { /** * Constructeur par defaut : initialise toutes les variables et les tableaux */ - public Statistics(){ - maDB=new DataBase(); + public Statistics() { + maDB = new DataBase(); maDB.getConnection(); - numSelect =new long[5]; - numId =new long[50][4000]; + numSelect = new long[5]; + numId = new long[50][4000]; numCpt = new long[50][2]; - combi1Id =new long[50][4000]; + combi1Id = new long[50][4000]; combi1Cpt = new long[50]; - num1_bonusId =new long[11][4000]; + num1_bonusId = new long[11][4000]; num1_bonusCpt = new long[11]; - num2_bonusId =new long[11][4000]; + num2_bonusId = new long[11][4000]; num2_bonusCpt = new long[11]; - num3_bonusId =new long[11][4000]; + num3_bonusId = new long[11][4000]; num3_bonusCpt = new long[11]; - combi2Id=new long[50][4000]; - combi2Cpt=new long[50]; - bonusId =new long[11][4000]; - bonusCpt=new long[11][2]; - conn= maDB.getConnection(); + combi2Id = new long[50][4000]; + combi2Cpt = new long[50]; + bonusId = new long[11][4000]; + bonusCpt = new long[11][2]; + conn = maDB.getConnection(); } /** * Methode renvoyant les numeros avec leur frequence d'apparition - * @throws SQLException + * * @return affichage numeros + * @throws SQLException */ public String numero1() throws SQLException { System.out.println("debut numero1"); - int k=0, numprec=0, l=0; - ResultSet rs=null; + int k = 0, numprec = 0, l = 0; + ResultSet rs = null; String sql; int j = 0; - for (int i=1; i<6;i++) { + for (int i = 1; i < 6; i++) { sql = "SELECT Test_Table.boule_" + i + ",Count(*) as 'cnt' FROM myny.Test_Table GROUP BY Test_Table.boule_" + i + "; "; try { conn = maDB.getConnection(); @@ -91,11 +92,11 @@ public class Statistics { } j++; } - j=0; + j = 0; } //for (int i=0; i<50;i++) { System.out.println(i+" :"+ numCpt[i][1]); } - for (int i=1; i<=5;i++) { + for (int i = 1; i <= 5; i++) { sql = "SELECT Test_Table.annee_numero_de_tirage, Test_Table.boule_" + i + " FROM myny.Test_Table ORDER BY Test_Table.boule_" + i + "; "; try { conn = maDB.getConnection(); @@ -114,48 +115,51 @@ public class Statistics { //rs.next(); while (rs.next()) { //System.out.println(numprec+", "+rs.getInt(2)); - if(numprec!=rs.getInt(2)) {k = 0;} - while(numId[rs.getInt(2)][k]!=0){ + if (numprec != rs.getInt(2)) { + k = 0; + } + while (numId[rs.getInt(2)][k] != 0) { k++; } - numId[rs.getInt(2)][k]=rs.getInt(1); + numId[rs.getInt(2)][k] = rs.getInt(1); //System.out.println(numId[rs.getInt(2)][k]); - numprec=rs.getInt(2); + numprec = rs.getInt(2); } - k=0; + k = 0; //j=0; } String s = null; - for (int i=1; i<50;i++) { - s = i+":\n"; - while(numId[i][l]!=0){ - s = s +numId[i][l]+", "; + for (int i = 1; i < 50; i++) { + s = i + ":\n"; + while (numId[i][l] != 0) { + s = s + numId[i][l] + ", "; l++; } - l=0; + l = 0; } return s; } /** * Methode renvoyant les combinaisons a deux numeros en fonction du premier numero choisi + * * @param chiffre1 premiere combinaison - * @throws SQLException * @return affichage combinaison + * @throws SQLException */ public String combinaison2(int chiffre1) throws SQLException { numero1(); System.out.println("debut combinaison2"); - numSelect[1]=chiffre1; - int j=0, k=0, l=0, cpt=0; - for(int i=1;i<50;i++) { + numSelect[1] = chiffre1; + int j = 0, k = 0, l = 0, cpt = 0; + for (int i = 1; i < 50; i++) { if (i != chiffre1) { while (numId[chiffre1][j] != 0) { while (numId[i][k] != 0) { //System.out.println(numId[i][k] +"=="+ numId[chiffre1][j]); if (numId[i][k] == numId[chiffre1][j]) { combi1Cpt[i]++; - combi1Id[i][cpt++]=numId[i][k]; + combi1Id[i][cpt++] = numId[i][k]; } k++; } @@ -164,44 +168,45 @@ public class Statistics { } j = 0; } - cpt=0; + cpt = 0; } String s = null; - for (int i=1; i<50;i++) { + for (int i = 1; i < 50; i++) { /*for (int p=1; p<50;p++) { System.out.print(combi1Id[i][p]+", "); }*/ - s = i+": "+combi1Cpt[i]+"\n"; - while(combi1Id[i][l]!=0){ - s = s + combi1Id[i][l]+", "; + s = i + ": " + combi1Cpt[i] + "\n"; + while (combi1Id[i][l] != 0) { + s = s + combi1Id[i][l] + ", "; l++; } - l=0; + l = 0; } return s; } /** * Methode renvoyant les combinaisons a trois numeros en fonction des deux numeros choisi + * * @param chiffre1 * @param chiffre2 - * @throws SQLException * @return affichage combinaison + * @throws SQLException */ public String combinaison3(int chiffre1, int chiffre2) throws SQLException { numero1(); combinaison2(chiffre1); System.out.println("debut combinaison3"); - numSelect[2]=chiffre2; - int j=0, k=0, m=0, cpt=0; - for(int i=1;i<50;i++) { - if (i != chiffre1 && i!=chiffre2) { - while (combi1Id[chiffre2][j] != 0){ + numSelect[2] = chiffre2; + int j = 0, k = 0, m = 0, cpt = 0; + for (int i = 1; i < 50; i++) { + if (i != chiffre1 && i != chiffre2) { + while (combi1Id[chiffre2][j] != 0) { while (numId[i][k] != 0) { //System.out.println(numId[i][k] +"=="+ combi1Id[chiffre2][j]); if (numId[i][k] == combi1Id[chiffre2][j]) { combi2Cpt[i]++; - combi2Id[i][cpt++]=numId[i][k]; + combi2Id[i][cpt++] = numId[i][k]; } k++; } @@ -210,33 +215,34 @@ public class Statistics { } j = 0; } - cpt=0; + cpt = 0; } String s = null; - for (int i=1; i<50;i++) { + for (int i = 1; i < 50; i++) { /*for (int p=1; p<50;p++) { System.out.print(combi1Id[i][p]+", "); }*/ - s = i+": "+combi2Cpt[i]+"\n"; - while(combi2Id[i][k]!=0){ - s = s+ combi2Id[i][k]+", "; + s = i + ": " + combi2Cpt[i] + "\n"; + while (combi2Id[i][k] != 0) { + s = s + combi2Id[i][k] + ", "; k++; } System.out.println(); - k=0; + k = 0; } return s; } /** * Methode renvoyant les numeros bonus avec leur frequence d'apparition - * @throws SQLException + * * @return affichage numero bonus + * @throws SQLException */ public String bonus() throws SQLException { System.out.println("debut bonus"); - int k=0, numprec=0, l=0; - ResultSet rs=null; + int k = 0, numprec = 0, l = 0; + ResultSet rs = null; String sql; sql = "SELECT Test_Table.numero_chance,Count(*) as 'cnt' FROM myny.Test_Table GROUP BY Test_Table.numero_chance; "; try { @@ -257,8 +263,8 @@ public class Statistics { bonusCpt[rs.getInt(1)][0] = rs.getInt(1); bonusCpt[rs.getInt(1)][1] = rs.getLong(2); } - for (int i=0; i<11;i++) { - System.out.println(i+" :"+ bonusCpt[i][1]); + for (int i = 0; i < 11; i++) { + System.out.println(i + " :" + bonusCpt[i][1]); } sql = "SELECT Test_Table.annee_numero_de_tirage, Test_Table.numero_chance FROM myny.Test_Table ORDER BY Test_Table.numero_chance; "; try { @@ -278,167 +284,29 @@ public class Statistics { //rs.next(); while (rs.next()) { //System.out.println(numprec+", "+rs.getInt(2)); - if(numprec!=rs.getInt(2)) {k = 0;} - while(bonusId[rs.getInt(2)][k]!=0){ + if (numprec != rs.getInt(2)) { + k = 0; + } + while (bonusId[rs.getInt(2)][k] != 0) { k++; } - bonusId[rs.getInt(2)][k]=rs.getInt(1); + bonusId[rs.getInt(2)][k] = rs.getInt(1); System.out.println(bonusId[rs.getInt(2)][k]); - numprec=rs.getInt(2); + numprec = rs.getInt(2); } - k=0; + k = 0; //j=0; String s = null; - for (int i=1; i<11;i++) { - s = i+":"+bonusCpt[i][1]+"\n"; - while(bonusId[i][l]!=0){ - s = s + bonusId[i][l]+", "; + for (int i = 1; i < 11; i++) { + s = i + ":" + bonusCpt[i][1] + "\n"; + while (bonusId[i][l] != 0) { + s = s + bonusId[i][l] + ", "; l++; } System.out.println(); - l=0; + l = 0; } return s; } - - /** - * Methode renvoyant les numeros bonus en fonction des combinaisons a un numeros - * @param chiffre1 - * @throws SQLException - * @return affchage combinaison a un element et numero bonus - */ - public String bonusCombi1(int chiffre1) throws SQLException { - numero1(); - this.bonus(); - System.out.println("debut bonus"); - numSelect[1]=chiffre1; - int j=0, k=0, l=0, cpt=0; - for(int i=1;i<11;i++) { - while (numId[chiffre1][j] != 0) { - while (bonusId[i][k] != 0) { - //System.out.println(bonusId[i][k] +"=="+ numId[chiffre1][j]); - if (bonusId[i][k] == numId[chiffre1][j]) { - num1_bonusCpt[i]++; - num1_bonusId[i][cpt++]=bonusId[i][k]; - j++; - } - k++; - } - k = 0; - j++; - } - j = 0; - cpt=0; - } - String s = null; - for (int i=1; i<11;i++) { - /*for (int p=1; p<50;p++) { - System.out.print(combi1Id[i][p]+", "); - }*/ - System.out.println(i+": "+num1_bonusCpt[i]); - while(num1_bonusId[i][l]!=0){ - System.out.print(num1_bonusId[i][l]+", "); - l++; - } - System.out.println(); - l=0; - } - return s; - } - - /** - * Methode renvoyant les numeros bonus en fonction des combinaisons a deux numeros - * @param chiffre1 - * @param chiffre2 - * @throws SQLException - * @return affchage combinaison a deux elements et numero bonus - */ - public String bonusCombi2(int chiffre1, int chiffre2) throws SQLException { - combinaison2(chiffre1); - bonus(); - System.out.println("debut bonusCombi2"); - numSelect[1]=chiffre1; - numSelect[2]=chiffre2; - int j=0, k=0, l=0, cpt=0; - for(int i=1;i<11;i++) { - while (combi1Id[chiffre2][j] != 0) { - while (bonusId[i][k] != 0) { - //System.out.println(bonusId[i][k] +"=="+ combi1Id[chiffre2][j]); - if (bonusId[i][k] == combi1Id[chiffre2][j]) { - num2_bonusCpt[i]++; - num2_bonusId[i][cpt++]=bonusId[i][k]; - j++; - } - k++; - } - k = 0; - j++; - } - j = 0; - cpt=0; - } - String s = null; - for (int i=1; i<11;i++) { - /*for (int p=1; p<50;p++) { - System.out.print(combi1Id[i][p]+", "); - }*/ - System.out.println(i+": "+num2_bonusCpt[i]); - while(num2_bonusId[i][l]!=0){ - System.out.print(num2_bonusId[i][l]+", "); - l++; - } - System.out.println(); - l=0; - } - return s; - } - - /** - * Methode renvoyant les numeros bonus en fonction des combinaisons a trois numeros - * @param chiffre1 - * @param chiffre2 - * @param chiffre3 - * @throws SQLException - * @return affchage combinaison a trois elements et numero bonus - */ - public String bonusCombi3(int chiffre1, int chiffre2, int chiffre3) throws SQLException { - combinaison3(chiffre1, chiffre2); - bonus(); - System.out.println("debut bonusCombi3"); - numSelect[1]=chiffre1; - numSelect[2]=chiffre2; - numSelect[3]=chiffre3; - int j=0, k=0, l=0, cpt=0; - while (combi2Id[chiffre3][j] != 0) { - for(int i=1;i<11;i++) { - while (bonusId[i][k] != 0) { - //System.out.println(combi2Id[chiffre3][j] +"=="+ bonusId[i][k]); - if (bonusId[i][k] == combi2Id[chiffre3][j]) { - num3_bonusCpt[i]++; - num3_bonusId[i][cpt++]=bonusId[i][k]; - j++; - } - k++; - } - k = 0; - } - cpt=0; - j++; - } - for (int i=1; i<11;i++) { - /*for (int p=1; p<50;p++) { - System.out.print(combi1Id[i][p]+", "); - }*/ - System.out.println(i+": "+num3_bonusCpt[i]); - while(num3_bonusId[i][l]!=0){ - System.out.print(num3_bonusId[i][l]+", "); - l++; - } - System.out.println(); - l=0; - } - String s = null; - return s; - - } } +