Bonjour voila je dois faire une petite appli dico en tcp pour un projet d'anglais et je suis bloqué.
J'ai mon client et mon serveur et 2 autres classes (partie qui est un tableau et dico qui permet de faire la traduction du mot francais a anglais).
Je ne sais pas comment appeler ma classe appli pour faire la translation grace au dico.
Je vous montre mes classes.
Serveur:
ClientCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package multino; import java.net.*; public class TraductionServeurno { public static void main(String[] args) throws Exception{ ServerSocket server=new ServerSocket(8000); System.out.println("Serveur en attente de connexion..."); while(true){ Socket s=server.accept(); clientba.TraductionClientba t=new clientno.TraductionClientno(s); t.start(); } } }
partieCode:
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 package clientno; import java.io.*; import java.net.*; public class TraductionClientno extends Thread { private Socket s; public TraductionClientno(Socket s){ this.s=s; } public void run(){ OutputStream os=null; InputStream is=null; try { os=s.getOutputStream(); PrintWriter ecriture=new PrintWriter(os,true); is=s.getInputStream(); BufferedReader lecture=new BufferedReader(new InputStreamReader(is)); // Explication de l'intéraction ecriture.println("traduire en anglais chacun des mots suivants:"); // boucle de lecture/ecriture reseau String ligne=null; String ip=s.getInetAddress().getHostName(); while(true){ ligne=lecture.readLine(); ecriture.println(ligne.toUpperCase()); System.out.println(ip+": "+ligne); } }catch(IOException e){ System.err.println("erreur: "+e.getMessage()); }finally{ try { if(os!=null) os.close(); }catch(IOException e){ System.err.println("erreur en fermeture: "+e.getMessage()); } try { if(is!=null) is.close(); }catch(IOException e){ System.err.println("erreur en fermeture: "+e.getMessage()); } try { if(s!=null) s.close(); }catch(IOException e){ System.err.println("erreur en fermeture: "+e.getMessage()); } } }// fin de run }// fin de classe
DictionnaireCode:
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 package util; import java.io.Serializable; public class Partie implements Serializable { private static final long serialVersionUID = -7683039505063936339L; private static final int NBMOTS=5; private String[][] mots; public Partie(){ this(NBMOTS); } public Partie(int nbMots){ if(nbMots==0){ nbMots=NBMOTS; } mots=new String[nbMots][3]; for(int i=0;i<mots.length;i++){ mots[i][0]=Dictionnaire.getMotFrançais(); mots[i][1]=null; mots[i][2]=null; } } public String getMotFrancais(int i){ return mots[i][0]; } public String getMotAnglais(int i){ return mots[i][1]; } public String getReponse(int i){ return mots[i][2]; } public void setReponse(int i, String motAnglaisPropose){ mots[i][2]=motAnglaisPropose; } public int getNbMots(){ return mots.length; } public int getBonnesReponses(){ int n=0; for(String[] reponse: mots){ if(reponse[1].equals(reponse[2])){ n++; } } return n; } public int getScore(){ return 100*getBonnesReponses()/mots.length; } public void setMotsAnglais(){ for(int i=0;i<mots.length;i++){ mots[i][1]=Dictionnaire.getMotAnglais(mots[i][0]); } } }
Code:
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 package util; import java.util.HashMap; public class Dictionnaire { private static int FRANCAIS=1; private static int ANGLAIS=0; private static String[][] liste={ {"house", "maison"}, {"bed", "lit"}, {"chair", "chaise"}, {"door", "porte"}, {"wall", "mur"}, {"table", "table"}, {"wall", "mur"}, {"roof", "toit"}, {"window", "fenetre"}, {"floor", "plancher"}, {"armchair", "fauteuil"}, {"car", "voiture"}, {"train", "train"}, {"plane", "avion"}, {"boat", "bateau"}, {"meat", "viande"}, {"fish", "poisson"}, {"fruit", "fruit"}, {"potatoe", "pomme de terre"}, {"apple", "pomme"}, {"pineapple", "ananas"}, {"strawberry", "fraise"}, {"banana", "banane"}, {"plane", "avion"}, {"bird", "oiseau"}, {"water", "eau"}, {"bottle", "bouteille"}, {"sirup", "sirop"}, {"wine", "vin"}, {"cup", "tasse"}, {"tea", "the"}, {"coffee", "cafe"}, {"milk", "lait"}, {"money", "argent"}, {"meeting", "reunion"}, {"fire", "feu"}, {"light", "lumiere"}, {"traffic", "circulation"}, {"travel", "voyage"}, {"smoke", "fumee"}, {"food", "nourriture"}, {"sea", "mer"}, {"sun", "soleil"}, {"sky", "ciel"}, {"beach", "plage"}, {"wave", "vague"}, {"holiday", "vacance"}, {"head", "tete"}, {"arm", "bras"}, {"leg", "jambe"}, {"knee", "genou"}, {"hand", "main"}, {"foot", "pied"}, {"hair", "cheveu"}, {"nose", "nez"}, {"eye", "oeil"}, {"mouth", "bouche"}, {"ear", "oreille"}, {"tooth", "dent"}, {"month", "mois"}, {"year", "annee"}, {"day", "jour"}, {"morning", "matin"}, {"afternoon", "apres-midi"}, {"night", "nuit"}, {"beginning", "debut"}, {"end", "fin"}, {"height", "hauteur"}, {"wight", "largeur"}, {"weight", "poids"}, {"field", "champ"}, {"freedom", "liberte"} }; private static HashMap<String, String> dico=new HashMap<String, String> (); static{ for(String[] c: liste){ dico.put(c[FRANCAIS],c[ANGLAIS]); } } public static String getMotFrançais(){ int alea=(int)(liste.length*Math.random()); System.out.println("alea:"+alea); return liste[alea][FRANCAIS]; } public static String getMotAnglais(String motFrancais){ return dico.get(motFrancais); } }