Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

/* Mohamed Anis MEKKI - 2003 (c) */ import java.lang.*; import java.util.*; import java.lang.*; import java.lang.System; public class symbol { String symb; double prob; /* Remarque importante : Les variables déclarées statiques, sont toujours les mêmes pour toutes les instances d'une même classe ..! Modifier une variable static pour une certaine instance, modifiera cette variable pour toutes les instances ! */ public symbol(String s,double d) { this.symb=s; this.prob=d; } public void show() { String proba = Double.toString(this.prob); String exp=proba.substring(proba.length()-3); int format = Math.min(6,(proba.length())); proba = proba.substring(0,format); int i = proba.length(); if (exp.substring((exp.length()-3),(exp.length()-1)).equals("E-")) { proba = proba.substring(0,1); proba = proba+exp; } System.out.println("Symbole : "+this.symb); System.out.println("Probabilité : "+proba); } public void show_tree() { String proba = Double.toString(this.prob); String exp=proba.substring(proba.length()-3); int format = Math.min(4,(proba.length())); proba = proba.substring(0,format); int i = proba.length(); if ( i != 4 ) { proba=proba+"0"; } if (exp.substring((exp.length()-3),(exp.length()-1)).equals("E-")) { proba = proba.substring(0,1); proba = proba+exp; } System.out.print("("+this.symb+","+proba+")"); } public void show_prob() { String proba = Double.toString(this.prob); String exp=proba.substring(proba.length()-3); int format = Math.min(4,(proba.length())); proba = proba.substring(0,format); int i = proba.length(); if ( i != 4 ) { proba=proba+"0"; } if (exp.substring((exp.length()-3),(exp.length()-1)).equals("E-")) { proba = proba.substring(0,1); proba = proba+exp; } System.out.print("("+proba+")"); } public symbol combine(symbol s2) { symbol s_res = new symbol((symb+s2.symb),(prob*s2.prob)); return(s_res); } public symbol add (symbol s2) { symbol s_res = new symbol(symb+"-"+s2.symb,(prob+s2.prob)); return(s_res); } public static void main(String s[]) { symbol[] a = new symbol[3] ,A = new symbol[9]; int i=0,j=0,k=0; a[0] = new symbol("A1",0.8); a[1] = new symbol("A2",0.1); a[2] = new symbol("A3",0.1); while (i<3) { while (j<3) { A[k] = a[i].combine(a[j]); k++; j++; } j=0; i++; } i=0; k=0; while (i<3) { a[i].show(); i++; } while (k<9) { A[k].show(); k++; } }//fin main() }// fin symbol