Commit 4fe45579faae721fe76c7bc88bf71eb3175bc9e9
1 parent
8112a2dd
fonction cycle op binaires et exception
Showing
12 changed files
with
69 additions
and
20 deletions
Show diff stats
src/noyau/Addition.java
... | ... | @@ -13,7 +13,9 @@ public class Addition extends OperationBinaire { |
13 | 13 | public double eval() { |
14 | 14 | |
15 | 15 | if (!creerCycle(gauche) && !creerCycle(droite)) |
16 | - return gauche.getValeur() + droite.getValeur(); | |
16 | + return (double) gauche.getValue() + droite.getValue(); | |
17 | + else | |
18 | + return 0; | |
17 | 19 | |
18 | 20 | } |
19 | 21 | ... | ... |
src/noyau/Case.java
... | ... | @@ -23,9 +23,13 @@ public class Case { |
23 | 23 | this.formula = formula; |
24 | 24 | } |
25 | 25 | |
26 | - public Double getValue() { | |
26 | + public double getValue() { | |
27 | 27 | return this.value; |
28 | 28 | } |
29 | + | |
30 | + public List<Case> getUsedIn() { | |
31 | + return this.usedIn; | |
32 | + } | |
29 | 33 | |
30 | 34 | public void setValue(Double value) { |
31 | 35 | this.value = value; | ... | ... |
src/noyau/Division.java
1 | 1 | package noyau; |
2 | 2 | |
3 | +import noyau.exception.CellNotFoundException; | |
4 | +import noyau.exception.DivisionByZeroException; | |
5 | + | |
3 | 6 | public class Division extends OperationBinaire{ |
4 | 7 | |
5 | 8 | Division(Case g,Case d){ |
... | ... | @@ -9,13 +12,23 @@ public class Division extends OperationBinaire{ |
9 | 12 | |
10 | 13 | |
11 | 14 | |
12 | - public double eval() { | |
15 | + public double eval() throws DivisionByZeroException { | |
13 | 16 | |
14 | 17 | try{ |
15 | 18 | if (!creerCycle(gauche) && !creerCycle(droite)) |
16 | - return gauche.getValeur() / droite.getValeur(); | |
19 | + | |
20 | + return gauche.getValue()/droite.getValue(); | |
21 | + else | |
22 | + return 0; | |
23 | + } | |
24 | + catch(ArithmeticException ex){ | |
25 | + throw new DivisionByZeroException(); | |
17 | 26 | } |
18 | - catch(ArithmeticException ex){} | |
27 | + | |
28 | + | |
29 | + | |
30 | + | |
31 | + | |
19 | 32 | } |
20 | 33 | |
21 | 34 | ... | ... |
src/noyau/Fonctions.java
... | ... | @@ -12,8 +12,8 @@ abstract public class Fonctions extends Formule { |
12 | 12 | |
13 | 13 | public boolean creerCycle(Case uneCase){ |
14 | 14 | |
15 | - //if (!listePlage.contains(uneCase) && uneCase.utiliseDans.size()==0) | |
16 | - return false; | |
15 | + return listCases.contains(uneCase); | |
16 | + | |
17 | 17 | |
18 | 18 | |
19 | 19 | ... | ... |
src/noyau/Formule.java
1 | 1 | package noyau; |
2 | 2 | |
3 | +import noyau.exception.DivisionByZeroException; | |
4 | + | |
3 | 5 | abstract public class Formule { |
4 | 6 | |
5 | 7 | abstract public String toString(); |
6 | - abstract public double eval(); | |
7 | - | |
8 | + abstract public double eval() throws DivisionByZeroException; | |
9 | + abstract public boolean creerCycle(Case uneCase); | |
8 | 10 | |
9 | 11 | } | ... | ... |
src/noyau/Moyenne.java
... | ... | @@ -20,14 +20,16 @@ public class Moyenne extends Fonctions{ |
20 | 20 | |
21 | 21 | public double eval() { |
22 | 22 | |
23 | - double val=0; | |
23 | + double val=0.0; | |
24 | 24 | |
25 | 25 | try{ |
26 | 26 | for(int i=0; i<listCases.size(); i++) |
27 | - val += listCases.get(i).getValeur(); | |
27 | + val += listCases.get(i).getValue(); | |
28 | 28 | |
29 | - return val/ listCases.size(); | |
29 | + return (double)val/listCases.size(); | |
30 | + } | |
31 | + catch(ArithmeticException ex){ | |
32 | + return 0.0; | |
30 | 33 | } |
31 | - catch(ArithmeticException ex){} | |
32 | 34 | } |
33 | 35 | } | ... | ... |
src/noyau/Multiplication.java
... | ... | @@ -11,7 +11,9 @@ public class Multiplication extends OperationBinaire{ |
11 | 11 | public double eval() { |
12 | 12 | |
13 | 13 | if (!creerCycle(gauche) && !creerCycle(droite)) |
14 | - return gauche.getValeur() * droite.getValeur(); | |
14 | + return gauche.getValue() * droite.getValue(); | |
15 | + else | |
16 | + return 0; | |
15 | 17 | } |
16 | 18 | |
17 | 19 | ... | ... |
src/noyau/OperationBinaire.java
1 | 1 | package noyau; |
2 | 2 | |
3 | -import java.util.ArrayList; | |
3 | + | |
4 | +import noyau.exception.DivisionByZeroException; | |
5 | + | |
6 | + | |
4 | 7 | |
5 | 8 | abstract public class OperationBinaire extends Formule { |
6 | 9 | |
... | ... | @@ -9,12 +12,26 @@ abstract public class OperationBinaire extends Formule { |
9 | 12 | |
10 | 13 | abstract public String getFormuleDeveloppe(); |
11 | 14 | |
12 | - | |
15 | + abstract public double eval() throws DivisionByZeroException; | |
13 | 16 | |
14 | 17 | public boolean creerCycle(Case uneCase){ |
15 | 18 | |
16 | - //if (!listePlage.contains(uneCase) && uneCase.utiliseDans.size()==0) | |
17 | - return false; | |
19 | + | |
20 | + if (droite.containFormula() && !gauche.containFormula()) | |
21 | + return droite.getFormula().creerCycle(uneCase); | |
22 | + else { | |
23 | + if (!droite.containFormula() && gauche.containFormula()) | |
24 | + return gauche.getFormula().creerCycle(uneCase); | |
25 | + else{ | |
26 | + if (droite.containFormula() && gauche.containFormula()) | |
27 | + return gauche.getFormula().creerCycle(uneCase) && droite.getFormula().creerCycle(uneCase); | |
28 | + else{ | |
29 | + return (uneCase.getId()==droite.getId() || uneCase.getId()==gauche.getId()); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + } | |
34 | + | |
18 | 35 | |
19 | 36 | |
20 | 37 | ... | ... |
src/noyau/Somme.java
src/noyau/Soustraction.java
... | ... | @@ -12,7 +12,9 @@ public class Soustraction extends OperationBinaire{ |
12 | 12 | public double eval() { |
13 | 13 | |
14 | 14 | if (!creerCycle(gauche) && !creerCycle(droite)) |
15 | - return gauche.getValeur() - droite.getValeur(); | |
15 | + return gauche.getValue() - droite.getValue(); | |
16 | + else | |
17 | + return 0; | |
16 | 18 | } |
17 | 19 | |
18 | 20 | ... | ... |