Biblioteca Java - Blame information for rev 2
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mihai | 1 | package colectii.map; |
2 | import java.util.*; | ||
3 | import java.io.*; | ||
4 | |||
5 | public class Dictionar { | ||
6 | |||
7 | TreeMap dct = new TreeMap(); | ||
8 | |||
9 | public Dictionar() { | ||
10 | } | ||
11 | |||
12 | public void adaugaCuvant(String cuvant, String definitie) { | ||
13 | |||
14 | if(dct.containsKey(cuvant)){ | ||
15 | System.out.println("Modific cuvant existent!"); | ||
16 | } | ||
17 | else | ||
18 | { | ||
19 | System.out.println("Adauga cuvant nou."); | ||
20 | } | ||
21 | dct.put(cuvant, definitie); | ||
22 | |||
23 | } | ||
24 | |||
25 | public String cautaCuvant(String cuvant) { | ||
26 | return (String)dct.get(cuvant); | ||
27 | } | ||
28 | |||
29 | public void afisDictionar() { | ||
30 | System.out.println(this); | ||
31 | } | ||
32 | |||
33 | |||
34 | public static void main(String args[]) throws Exception { | ||
35 | Dictionar dict = new Dictionar(); | ||
36 | char raspuns; | ||
37 | String linie, explic; | ||
38 | BufferedReader fluxIn = new BufferedReader(new InputStreamReader(System.in)); | ||
39 | |||
40 | do { | ||
41 | System.out.println("Meniu"); | ||
42 | System.out.println("a - Adauga cuvant"); | ||
43 | System.out.println("c - Cauta cuvant"); | ||
44 | System.out.println("l - Listeaza dictionar"); | ||
45 | System.out.println("e - Iesi"); | ||
46 | |||
47 | linie = fluxIn.readLine(); | ||
48 | raspuns = linie.charAt(0); | ||
49 | |||
50 | switch(raspuns) { | ||
51 | case 'a': case 'A': | ||
52 | System.out.println("Introduceti cuvantul:"); | ||
53 | linie = fluxIn.readLine(); | ||
54 | if( linie.length()>1) { | ||
55 | System.out.println("Introduceti definitia:"); | ||
56 | explic = fluxIn.readLine(); | ||
57 | dict.adaugaCuvant(linie, explic); | ||
58 | } | ||
59 | break; | ||
60 | case 'c': case 'C': | ||
61 | System.out.println("Cuvant cautat:"); | ||
62 | linie = fluxIn.readLine(); | ||
63 | if( linie.length()>1) { | ||
64 | explic = dict.cautaCuvant(linie); | ||
65 | if (explic == null) | ||
66 | System.out.println("nu exista"); | ||
67 | else | ||
68 | System.out.println("Explicatie:"+explic); | ||
69 | } | ||
70 | break; | ||
71 | case 'l': case 'L': | ||
72 | System.out.println("Afiseaza:"); | ||
73 | dict.afisDictionar(); | ||
74 | break; | ||
75 | |||
76 | } | ||
77 | } while(raspuns!='e' && raspuns!='E'); | ||
78 | System.out.println("Program terminat."); | ||
79 | } | ||
80 | } |