diff --git a/grid.data b/grid.data index a77ad6f..7539639 100644 Binary files a/grid.data and b/grid.data differ diff --git a/grille.ser b/grille.ser new file mode 100644 index 0000000..711006c Binary files /dev/null and b/grille.ser differ diff --git a/makefile b/makefile new file mode 100644 index 0000000..796b9d1 --- /dev/null +++ b/makefile @@ -0,0 +1,15 @@ +JFLAGS = -g +JC = javac +.SUFFIXES: .java .class +.java.class: +$(JC) $(JFLAGS) $*.java + +CLASSES = +sources.txt + +default: classes + +classes: $(CLASSES:.java=.class) + +clean: +$(RM) *.class diff --git a/rapport_finale.md b/rapport_finale.md index 2f2b84f..f3a8a6a 100644 --- a/rapport_finale.md +++ b/rapport_finale.md @@ -395,6 +395,22 @@ de cycles (direct et indirect) ## 2. STRUCTURE DU PROJET +### PACKAGES,CLASSES,FICHIERS DE DONNÉES + L'implémentation du projet peut se résumer comme suit : ![PACKAGE](package.png) + + +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). + +### MODES D'UTILISATION + + +** Commandes de compilation**: + +MAKEFILE : + +find src -not \( -path src/kernel/test -prune \) -name \*.java |xargs -i javac -d bin {} -cp src/ + + diff --git a/src/app/Menu.java b/src/app/Menu.java new file mode 100644 index 0000000..fd34aab --- /dev/null +++ b/src/app/Menu.java @@ -0,0 +1,319 @@ +package app; + +import kernel.Cell; +import kernel.Formula; +import kernel.Grid; +import kernel.LanguageEnum; +import kernel.exception.BadSyntaxException; +import kernel.exception.CellNotFoundException; +import kernel.exception.CreateCycleException; +import kernel.exception.InvalidIntervalException; +import kernel.function.Average; +import kernel.function.Sum; +import kernel.operation.Addition; +import kernel.operation.Division; +import kernel.operation.Multiplication; +import kernel.operation.Subtraction; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + + + +public class Menu { + public static void main(String[] args) throws IOException, CellNotFoundException, CreateCycleException, BadSyntaxException { + File fichier = new File("grille.ser"); + + // ouverture d'un flux sur un fichier + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier)); + + Grid grid = new Grid(); + + Scanner in=new Scanner(System.in); + + + int choix=0; + String column=""; + String formula=""; + int line; + + myLanguage(); + do { + menu(); + System.out.print("VOTRE CHOIX? "); + choix = in.nextInt(); + switch (choix) { + case 1 : + try { + createCase(grid); + } catch (CreateCycleException | CellNotFoundException | BadSyntaxException e) { + + e.getMessage();} + break; + case 2 : + try { + setCase(grid); + } catch (CreateCycleException | CellNotFoundException | BadSyntaxException e) { + + e.getMessage();} + break; + case 3 : + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).getDevelopedFormula()); + break; + case 4 : + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).toString()); + + break; + case 5 : + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println(grid.getCell(column, line).getId()+ ": " + grid.getCell(column, line).getValue()); + + break; + case 6 : + + gridPrint(grid); + break; + + case 0: // quitter + } + } while (choix!=0); + + + + oos.writeObject(grid); + oos.close(); + System.out.println("\n Adiós"); + } + + + static void menu() { + 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"); + } + + static void createCase(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { + + Scanner in=new Scanner(System.in); + + String column=""; + String formula=""; + int line; + int choix=0; + double value; + do { + System.out.println("\n1: Case avec valeur\n2: Case avec formule\n0: Quitter"); + System.out.print("votre choix? "); + choix = in.nextInt(); + switch (choix) { + case 1 : + try { + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println("\n Entrez la valeur de la case"); + value=in.nextDouble(); + grid.createCell(column, line, value); + + } catch (InvalidIntervalException exception) { + System.out.println(exception.getMessage());} + break; + case 2 : + try { + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println("\n Entrez la formule (Ex: (A1+A2) ou SOMME(A1,A2)"); + formula=in.next(); + grid.createCell(column, line, generateFormulaWithString(formula, grid)); + + + } catch (InvalidIntervalException exception) { + System.out.println(exception.getMessage());} + break; + + + case 0: // quitter + } + } while (choix!=0); + + } + + + static void gridPrint(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { + + Scanner in=new Scanner(System.in); + + List cells = grid.getCells(); + int choix=0; + do { + System.out.println("\n1: Afficher cases avec valeurs\n2: Afficher cases avec formules\n3: Afficher cases avec formules dévéloppées\n0: Quitter"); + System.out.print("votre choix? "); + choix = in.nextInt(); + switch (choix) { + case 1 : + + + System.out.println("Affichage des valeurs :"); + for (Cell cell : cells) + System.out.println(cell.getId() + ": " + cell.getValue()); + break; + + case 2 : + System.out.println("Affichage des formules :"); + for (Cell cell : cells) + System.out.println(cell.getId() + ": " + cell.toString()); + + break; + + case 3 : + System.out.println("Affichage des formules développées :"); + for (Cell cell : cells) + System.out.println(cell.getId() + ": " + cell.getDevelopedFormula()); + + break; + case 0: // quitter + } + } while (choix!=0); + + } + + + + static void setCase(Grid grid) throws CreateCycleException, CellNotFoundException, BadSyntaxException { + + Scanner in=new Scanner(System.in); + + String column=""; + String formula=""; + int line; + int choix=0; + double value; + do { + System.out.println("\n1: Modifier case avec valeur\n2: Modifier case avec formule\n0: QUITTER"); + System.out.print("votre choix? "); + choix = in.nextInt(); + switch (choix) { + case 1 : + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println("\n Entrez la valeur de la case"); + value=in.nextDouble(); + grid.setValue(column, line, value); + break; + case 2 : + System.out.println("\n Entrez la colonne de la case"); + column= in.next(); + System.out.println("\n Entrez la ligne de la case"); + line= in.nextInt(); + System.out.println("\n Entrez la formule (Ex: (A1+A2) ou SOMME(A1,A2)"); + formula=in.next(); + grid.setFormula(column, line, generateFormulaWithString(formula, grid)); + break; + + + case 0: // quitter + } + } while (choix!=0); + + } + + private static Formula generateFormulaWithString(String input,Grid grid) throws CellNotFoundException, BadSyntaxException { + Pattern functionPattern = Pattern.compile("([A-Z]+)\\(([A-Z0-9,]+)\\)"); + Matcher functionMatcher = functionPattern.matcher(input); + + if (functionMatcher.matches()) { + List cells = Arrays.stream(functionMatcher.group(2).split(",")) + .map(c -> grid.getCell(c)) + .collect(Collectors.toList()); + + if (cells.contains(null)) + throw new CellNotFoundException(); + + cells = cells.stream().filter(Objects::nonNull).collect(Collectors.toList()); + + switch (functionMatcher.group(1)) { + case "SUM": + case "SOMME": + return new Sum(cells); + case "AVERAGE": + case "MOYENNE": + return new Average(cells); + } + } else { + Pattern binaryOperationPattern = Pattern.compile("([A-Z]+[0-9]+)([+\\-*/])([A-Z]+[0-9]+)"); + Matcher binaryOperationMatcher = binaryOperationPattern.matcher(input); + + if (!binaryOperationMatcher.matches()) + throw new BadSyntaxException(); + + Cell leftCell = grid.getCell(binaryOperationMatcher.group(1)); + Cell rightCell = grid.getCell(binaryOperationMatcher.group(3)); + + if (leftCell == null || rightCell == null) + throw new CellNotFoundException(); + + switch (binaryOperationMatcher.group(2)) { + case "+": + return new Addition(leftCell, rightCell); + case "-": + return new Subtraction(leftCell, rightCell); + case "*": + return new Multiplication(leftCell, rightCell); + case "/": + return new Division(leftCell, rightCell); + } + } + + return null; + } + + +static void myLanguage () { + + Scanner in=new Scanner(System.in); + + int choix=0; + System.out.println("\n1: Francais/French\n2: Anglais/English"); + System.out.println("votre choix? "); + choix = in.nextInt(); + switch (choix) { + case 1 : + Grid.language=LanguageEnum.FR; + + break; + case 2 : + Grid.language=LanguageEnum.EN; + break; + + } +} + + +} + + + diff --git a/src/kernel/Grid.java b/src/kernel/Grid.java index 70caa1d..9c27dfc 100644 --- a/src/kernel/Grid.java +++ b/src/kernel/Grid.java @@ -43,15 +43,18 @@ public class Grid implements Serializable { } public void setValue(String column, int line, double value) throws CellNotFoundException { + column = column.toUpperCase(); this.getCell(column, line).setValue(value); } public void setFormula(String column, int line, Formula formula) throws CellNotFoundException, CreateCycleException { + column = column.toUpperCase(); this.getCell(column, line).setFormula(formula); } public Cell getCell(String column, int line) throws CellNotFoundException { + column = column.toUpperCase(); Cell cell = this.cells.get(this.getCellId(column, line)); if (cell != null) @@ -69,18 +72,22 @@ public class Grid implements Serializable { } public double getValue(String column, int line) throws CellNotFoundException { + column = column.toUpperCase(); return this.getCell(column, line).getValue(); } public String getFormulaAsString(String column, int line) throws CellNotFoundException { + column = column.toUpperCase(); return this.getCell(column, line).toString(); } public String getDevelopedFormula(String column, int line) throws CellNotFoundException { + column = column.toUpperCase(); return this.getCell(column, line).getDevelopedFormula(); } private String getCellId(String column, int line) { + column = column.toUpperCase(); return column + line; } -- libgit2 0.21.2