Commit e4ef4371e106a9f5ef3d25e06c9b1d43da95a3e7
1 parent
178cc4eb
mm
Showing
6 changed files
with
357 additions
and
0 deletions
Show diff stats
grid.data
No preview for this file type
No preview for this file type
rapport_finale.md
@@ -395,6 +395,22 @@ de cycles (direct et indirect) | @@ -395,6 +395,22 @@ de cycles (direct et indirect) | ||
395 | 395 | ||
396 | ## 2. STRUCTURE DU PROJET | 396 | ## 2. STRUCTURE DU PROJET |
397 | 397 | ||
398 | +### PACKAGES,CLASSES,FICHIERS DE DONNÉES | ||
399 | + | ||
398 | L'implémentation du projet peut se résumer comme suit : | 400 | L'implémentation du projet peut se résumer comme suit : |
399 | 401 | ||
400 | ![PACKAGE](package.png) | 402 | ![PACKAGE](package.png) |
403 | + | ||
404 | + | ||
405 | +Le schéma ci-dessus nous montre que, l'implémentation est composé de 5 package (representant 5 repertoires) contenant des classes ( chaque classe est un fichier d'extension java). | ||
406 | + | ||
407 | +### MODES D'UTILISATION | ||
408 | + | ||
409 | + | ||
410 | +** Commandes de compilation**: | ||
411 | + | ||
412 | +MAKEFILE : | ||
413 | + | ||
414 | +find src -not \( -path src/kernel/test -prune \) -name \*.java |xargs -i javac -d bin {} -cp src/ | ||
415 | + | ||
416 | + |
@@ -0,0 +1,319 @@ | @@ -0,0 +1,319 @@ | ||
1 | +package app; | ||
2 | + | ||
3 | +import kernel.Cell; | ||
4 | +import kernel.Formula; | ||
5 | +import kernel.Grid; | ||
6 | +import kernel.LanguageEnum; | ||
7 | +import kernel.exception.BadSyntaxException; | ||
8 | +import kernel.exception.CellNotFoundException; | ||
9 | +import kernel.exception.CreateCycleException; | ||
10 | +import kernel.exception.InvalidIntervalException; | ||
11 | +import kernel.function.Average; | ||
12 | +import kernel.function.Sum; | ||
13 | +import kernel.operation.Addition; | ||
14 | +import kernel.operation.Division; | ||
15 | +import kernel.operation.Multiplication; | ||
16 | +import kernel.operation.Subtraction; | ||
17 | + | ||
18 | +import java.io.File; | ||
19 | +import java.io.FileOutputStream; | ||
20 | +import java.io.IOException; | ||
21 | +import java.io.ObjectOutputStream; | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.Arrays; | ||
24 | +import java.util.List; | ||
25 | +import java.util.Objects; | ||
26 | +import java.util.Scanner; | ||
27 | +import java.util.regex.Matcher; | ||
28 | +import java.util.regex.Pattern; | ||
29 | +import java.util.stream.Collectors; | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | +public class Menu { | ||
34 | + public static void main(String[] args) throws IOException, CellNotFoundException, CreateCycleException, BadSyntaxException { | ||
35 | + File fichier = new File("grille.ser"); | ||
36 | + | ||
37 | + // ouverture d'un flux sur un fichier | ||
38 | + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier)); | ||
39 | + | ||
40 | + Grid grid = new Grid(); | ||
41 | + | ||
42 | + Scanner in=new Scanner(System.in); | ||
43 | + | ||
44 | + | ||
45 | + int choix=0; | ||
46 | + String column=""; | ||
47 | + String formula=""; | ||
48 | + int line; | ||
49 | + | ||
50 | + myLanguage(); | ||
51 | + do { | ||
52 | + menu(); | ||
53 | + System.out.print("VOTRE CHOIX? "); | ||
54 | + choix = in.nextInt(); | ||
55 | + switch (choix) { | ||
56 | + case 1 : | ||
57 | + try { | ||
58 | + createCase(grid); | ||
59 | + } catch (CreateCycleException | CellNotFoundException | BadSyntaxException e) { | ||
60 | + | ||
61 | + e.getMessage();} | ||
62 | + break; | ||
63 | + case 2 : | ||
64 | + try { | ||
65 | + setCase(grid); | ||
66 | + } catch (CreateCycleException | CellNotFoundException | BadSyntaxException e) { | ||
67 | + | ||
68 | + e.getMessage();} | ||
69 | + break; | ||
70 | + case 3 : | ||
71 | + System.out.println("\n Entrez la colonne de la case"); | ||
72 | + column= in.next(); | ||
73 | + System.out.println("\n Entrez la ligne de la case"); | ||
74 | + line= in.nextInt(); | ||
75 | + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).getDevelopedFormula()); | ||
76 | + break; | ||
77 | + case 4 : | ||
78 | + System.out.println("\n Entrez la colonne de la case"); | ||
79 | + column= in.next(); | ||
80 | + System.out.println("\n Entrez la ligne de la case"); | ||
81 | + line= in.nextInt(); | ||
82 | + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).toString()); | ||
83 | + | ||
84 | + break; | ||
85 | + case 5 : | ||
86 | + System.out.println("\n Entrez la colonne de la case"); | ||
87 | + column= in.next(); | ||
88 | + System.out.println("\n Entrez la ligne de la case"); | ||
89 | + line= in.nextInt(); | ||
90 | + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).getValue()); | ||
91 | + | ||
92 | + break; | ||
93 | + case 6 : | ||
94 | + | ||
95 | + gridPrint(grid); | ||
96 | + break; | ||
97 | + | ||
98 | + case 0: // quitter | ||
99 | + } | ||
100 | + } while (choix!=0); | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + oos.writeObject(grid); | ||
105 | + oos.close(); | ||
106 | + System.out.println("\n Adiós"); | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + static void menu() { | ||
111 | + System.out.println("\n1: CREER UNE CASE \n2: MODIFIER UNE CASE\n3:AFFICHER FORMULE DEVELOPPEEE CASE\n4:AFFICHER FORMULE CASE\n5:AFFICHER VALEUR CASE\n6:AFFICHER GRILLE\n0: QUITTER"); | ||
112 | + } | ||
113 | + | ||
114 | + static void createCase(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { | ||
115 | + | ||
116 | + Scanner in=new Scanner(System.in); | ||
117 | + | ||
118 | + String column=""; | ||
119 | + String formula=""; | ||
120 | + int line; | ||
121 | + int choix=0; | ||
122 | + double value; | ||
123 | + do { | ||
124 | + System.out.println("\n1: Case avec valeur\n2: Case avec formule\n0: Quitter"); | ||
125 | + System.out.print("votre choix? "); | ||
126 | + choix = in.nextInt(); | ||
127 | + switch (choix) { | ||
128 | + case 1 : | ||
129 | + try { | ||
130 | + System.out.println("\n Entrez la colonne de la case"); | ||
131 | + column= in.next(); | ||
132 | + System.out.println("\n Entrez la ligne de la case"); | ||
133 | + line= in.nextInt(); | ||
134 | + System.out.println("\n Entrez la valeur de la case"); | ||
135 | + value=in.nextDouble(); | ||
136 | + grid.createCell(column, line, value); | ||
137 | + | ||
138 | + } catch (InvalidIntervalException exception) { | ||
139 | + System.out.println(exception.getMessage());} | ||
140 | + break; | ||
141 | + case 2 : | ||
142 | + try { | ||
143 | + System.out.println("\n Entrez la colonne de la case"); | ||
144 | + column= in.next(); | ||
145 | + System.out.println("\n Entrez la ligne de la case"); | ||
146 | + line= in.nextInt(); | ||
147 | + System.out.println("\n Entrez la formule (Ex: (A1+A2) ou SOMME(A1,A2)"); | ||
148 | + formula=in.next(); | ||
149 | + grid.createCell(column, line, generateFormulaWithString(formula, grid)); | ||
150 | + | ||
151 | + | ||
152 | + } catch (InvalidIntervalException exception) { | ||
153 | + System.out.println(exception.getMessage());} | ||
154 | + break; | ||
155 | + | ||
156 | + | ||
157 | + case 0: // quitter | ||
158 | + } | ||
159 | + } while (choix!=0); | ||
160 | + | ||
161 | + } | ||
162 | + | ||
163 | + | ||
164 | + static void gridPrint(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { | ||
165 | + | ||
166 | + Scanner in=new Scanner(System.in); | ||
167 | + | ||
168 | + List<Cell> cells = grid.getCells(); | ||
169 | + int choix=0; | ||
170 | + do { | ||
171 | + System.out.println("\n1: Afficher cases avec valeurs\n2: Afficher cases avec formules\n3: Afficher cases avec formules dévéloppées\n0: Quitter"); | ||
172 | + System.out.print("votre choix? "); | ||
173 | + choix = in.nextInt(); | ||
174 | + switch (choix) { | ||
175 | + case 1 : | ||
176 | + | ||
177 | + | ||
178 | + System.out.println("Affichage des valeurs :"); | ||
179 | + for (Cell cell : cells) | ||
180 | + System.out.println(cell.getId() + ": " + cell.getValue()); | ||
181 | + break; | ||
182 | + | ||
183 | + case 2 : | ||
184 | + System.out.println("Affichage des formules :"); | ||
185 | + for (Cell cell : cells) | ||
186 | + System.out.println(cell.getId() + ": " + cell.toString()); | ||
187 | + | ||
188 | + break; | ||
189 | + | ||
190 | + case 3 : | ||
191 | + System.out.println("Affichage des formules développées :"); | ||
192 | + for (Cell cell : cells) | ||
193 | + System.out.println(cell.getId() + ": " + cell.getDevelopedFormula()); | ||
194 | + | ||
195 | + break; | ||
196 | + case 0: // quitter | ||
197 | + } | ||
198 | + } while (choix!=0); | ||
199 | + | ||
200 | + } | ||
201 | + | ||
202 | + | ||
203 | + | ||
204 | + static void setCase(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { | ||
205 | + | ||
206 | + Scanner in=new Scanner(System.in); | ||
207 | + | ||
208 | + String column=""; | ||
209 | + String formula=""; | ||
210 | + int line; | ||
211 | + int choix=0; | ||
212 | + double value; | ||
213 | + do { | ||
214 | + System.out.println("\n1: Modifier case avec valeur\n2: Modifier case avec formule\n0: QUITTER"); | ||
215 | + System.out.print("votre choix? "); | ||
216 | + choix = in.nextInt(); | ||
217 | + switch (choix) { | ||
218 | + case 1 : | ||
219 | + System.out.println("\n Entrez la colonne de la case"); | ||
220 | + column= in.next(); | ||
221 | + System.out.println("\n Entrez la ligne de la case"); | ||
222 | + line= in.nextInt(); | ||
223 | + System.out.println("\n Entrez la valeur de la case"); | ||
224 | + value=in.nextDouble(); | ||
225 | + grid.setValue(column, line, value); | ||
226 | + break; | ||
227 | + case 2 : | ||
228 | + System.out.println("\n Entrez la colonne de la case"); | ||
229 | + column= in.next(); | ||
230 | + System.out.println("\n Entrez la ligne de la case"); | ||
231 | + line= in.nextInt(); | ||
232 | + System.out.println("\n Entrez la formule (Ex: (A1+A2) ou SOMME(A1,A2)"); | ||
233 | + formula=in.next(); | ||
234 | + grid.setFormula(column, line, generateFormulaWithString(formula, grid)); | ||
235 | + break; | ||
236 | + | ||
237 | + | ||
238 | + case 0: // quitter | ||
239 | + } | ||
240 | + } while (choix!=0); | ||
241 | + | ||
242 | + } | ||
243 | + | ||
244 | + private static Formula generateFormulaWithString(String input,Grid grid) throws CellNotFoundException, BadSyntaxException { | ||
245 | + Pattern functionPattern = Pattern.compile("([A-Z]+)\\(([A-Z0-9,]+)\\)"); | ||
246 | + Matcher functionMatcher = functionPattern.matcher(input); | ||
247 | + | ||
248 | + if (functionMatcher.matches()) { | ||
249 | + List<Cell> cells = Arrays.stream(functionMatcher.group(2).split(",")) | ||
250 | + .map(c -> grid.getCell(c)) | ||
251 | + .collect(Collectors.toList()); | ||
252 | + | ||
253 | + if (cells.contains(null)) | ||
254 | + throw new CellNotFoundException(); | ||
255 | + | ||
256 | + cells = cells.stream().filter(Objects::nonNull).collect(Collectors.toList()); | ||
257 | + | ||
258 | + switch (functionMatcher.group(1)) { | ||
259 | + case "SUM": | ||
260 | + case "SOMME": | ||
261 | + return new Sum(cells); | ||
262 | + case "AVERAGE": | ||
263 | + case "MOYENNE": | ||
264 | + return new Average(cells); | ||
265 | + } | ||
266 | + } else { | ||
267 | + Pattern binaryOperationPattern = Pattern.compile("([A-Z]+[0-9]+)([+\\-*/])([A-Z]+[0-9]+)"); | ||
268 | + Matcher binaryOperationMatcher = binaryOperationPattern.matcher(input); | ||
269 | + | ||
270 | + if (!binaryOperationMatcher.matches()) | ||
271 | + throw new BadSyntaxException(); | ||
272 | + | ||
273 | + Cell leftCell = grid.getCell(binaryOperationMatcher.group(1)); | ||
274 | + Cell rightCell = grid.getCell(binaryOperationMatcher.group(3)); | ||
275 | + | ||
276 | + if (leftCell == null || rightCell == null) | ||
277 | + throw new CellNotFoundException(); | ||
278 | + | ||
279 | + switch (binaryOperationMatcher.group(2)) { | ||
280 | + case "+": | ||
281 | + return new Addition(leftCell, rightCell); | ||
282 | + case "-": | ||
283 | + return new Subtraction(leftCell, rightCell); | ||
284 | + case "*": | ||
285 | + return new Multiplication(leftCell, rightCell); | ||
286 | + case "/": | ||
287 | + return new Division(leftCell, rightCell); | ||
288 | + } | ||
289 | + } | ||
290 | + | ||
291 | + return null; | ||
292 | + } | ||
293 | + | ||
294 | + | ||
295 | +static void myLanguage () { | ||
296 | + | ||
297 | + Scanner in=new Scanner(System.in); | ||
298 | + | ||
299 | + int choix=0; | ||
300 | + System.out.println("\n1: Francais/French\n2: Anglais/English"); | ||
301 | + System.out.println("votre choix? "); | ||
302 | + choix = in.nextInt(); | ||
303 | + switch (choix) { | ||
304 | + case 1 : | ||
305 | + Grid.language=LanguageEnum.FR; | ||
306 | + | ||
307 | + break; | ||
308 | + case 2 : | ||
309 | + Grid.language=LanguageEnum.EN; | ||
310 | + break; | ||
311 | + | ||
312 | + } | ||
313 | +} | ||
314 | + | ||
315 | + | ||
316 | +} | ||
317 | + | ||
318 | + | ||
319 | + |
src/kernel/Grid.java
@@ -43,15 +43,18 @@ public class Grid implements Serializable { | @@ -43,15 +43,18 @@ public class Grid implements Serializable { | ||
43 | } | 43 | } |
44 | 44 | ||
45 | public void setValue(String column, int line, double value) throws CellNotFoundException { | 45 | public void setValue(String column, int line, double value) throws CellNotFoundException { |
46 | + column = column.toUpperCase(); | ||
46 | this.getCell(column, line).setValue(value); | 47 | this.getCell(column, line).setValue(value); |
47 | } | 48 | } |
48 | 49 | ||
49 | public void setFormula(String column, int line, Formula formula) throws CellNotFoundException, | 50 | public void setFormula(String column, int line, Formula formula) throws CellNotFoundException, |
50 | CreateCycleException { | 51 | CreateCycleException { |
52 | + column = column.toUpperCase(); | ||
51 | this.getCell(column, line).setFormula(formula); | 53 | this.getCell(column, line).setFormula(formula); |
52 | } | 54 | } |
53 | 55 | ||
54 | public Cell getCell(String column, int line) throws CellNotFoundException { | 56 | public Cell getCell(String column, int line) throws CellNotFoundException { |
57 | + column = column.toUpperCase(); | ||
55 | Cell cell = this.cells.get(this.getCellId(column, line)); | 58 | Cell cell = this.cells.get(this.getCellId(column, line)); |
56 | 59 | ||
57 | if (cell != null) | 60 | if (cell != null) |
@@ -69,18 +72,22 @@ public class Grid implements Serializable { | @@ -69,18 +72,22 @@ public class Grid implements Serializable { | ||
69 | } | 72 | } |
70 | 73 | ||
71 | public double getValue(String column, int line) throws CellNotFoundException { | 74 | public double getValue(String column, int line) throws CellNotFoundException { |
75 | + column = column.toUpperCase(); | ||
72 | return this.getCell(column, line).getValue(); | 76 | return this.getCell(column, line).getValue(); |
73 | } | 77 | } |
74 | 78 | ||
75 | public String getFormulaAsString(String column, int line) throws CellNotFoundException { | 79 | public String getFormulaAsString(String column, int line) throws CellNotFoundException { |
80 | + column = column.toUpperCase(); | ||
76 | return this.getCell(column, line).toString(); | 81 | return this.getCell(column, line).toString(); |
77 | } | 82 | } |
78 | 83 | ||
79 | public String getDevelopedFormula(String column, int line) throws CellNotFoundException { | 84 | public String getDevelopedFormula(String column, int line) throws CellNotFoundException { |
85 | + column = column.toUpperCase(); | ||
80 | return this.getCell(column, line).getDevelopedFormula(); | 86 | return this.getCell(column, line).getDevelopedFormula(); |
81 | } | 87 | } |
82 | 88 | ||
83 | private String getCellId(String column, int line) { | 89 | private String getCellId(String column, int line) { |
90 | + column = column.toUpperCase(); | ||
84 | return column + line; | 91 | return column + line; |
85 | } | 92 | } |
86 | 93 |