Commit d8507aeed14b0691e99f8de61e8dce7c46dfb58e
1 parent
3bdcb2a4
Fichiers
Showing
11 changed files
with
264 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,32 @@ |
1 | +package noyau; | |
2 | + | |
3 | +import java.util.stream.Collectors; | |
4 | + | |
5 | +public class Addition extends OperationBinaire { | |
6 | + | |
7 | + Addition(Case g,Case d){ | |
8 | + gauche=g; | |
9 | + droite=d; | |
10 | + } | |
11 | + | |
12 | + | |
13 | + public double eval() { | |
14 | + | |
15 | + if (!creerCycle(gauche) && !creerCycle(droite)) | |
16 | + return gauche.getValeur() + droite.getValeur(); | |
17 | + | |
18 | + } | |
19 | + | |
20 | + | |
21 | + public String toString(){ | |
22 | + | |
23 | + return gauche.getId() +" + " + droite.getId() ; | |
24 | + } | |
25 | + | |
26 | + | |
27 | + public String getFormuleDeveloppe(){ | |
28 | + | |
29 | + return ""; | |
30 | + } | |
31 | + | |
32 | +} | ... | ... |
... | ... | @@ -0,0 +1,34 @@ |
1 | +package noyau; | |
2 | + | |
3 | +public class Division extends OperationBinaire{ | |
4 | + | |
5 | + Division(Case g,Case d){ | |
6 | + gauche=g; | |
7 | + droite=d; | |
8 | + } | |
9 | + | |
10 | + | |
11 | + | |
12 | + public double eval() { | |
13 | + | |
14 | + try{ | |
15 | + if (!creerCycle(gauche) && !creerCycle(droite)) | |
16 | + return gauche.getValeur() / droite.getValeur(); | |
17 | + } | |
18 | + catch(ArithmeticException ex){} | |
19 | + } | |
20 | + | |
21 | + | |
22 | + public String toString(){ | |
23 | + | |
24 | + return gauche.getId() +" / " + droite.getId() ; | |
25 | + } | |
26 | + | |
27 | + | |
28 | + | |
29 | + public String getFormuleDeveloppe(){ | |
30 | + | |
31 | + return ""; | |
32 | + } | |
33 | + | |
34 | +} | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +package noyau; | |
2 | + | |
3 | +import java.util.*; | |
4 | + | |
5 | +abstract public class Fonctions extends Formule { | |
6 | + | |
7 | + ArrayList<Case> listCases = new ArrayList<Case>(); | |
8 | + | |
9 | + abstract public String getFormuleDeveloppe(); | |
10 | + | |
11 | + | |
12 | + | |
13 | + public boolean creerCycle(Case uneCase){ | |
14 | + | |
15 | + //if (!listePlage.contains(uneCase) && uneCase.utiliseDans.size()==0) | |
16 | + return false; | |
17 | + | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + } | |
23 | + | |
24 | + | |
25 | +} | ... | ... |
src/noyau/Grille.java
... | ... | @@ -0,0 +1,33 @@ |
1 | +package noyau; | |
2 | + | |
3 | +import java.util.stream.Collectors; | |
4 | + | |
5 | +public class Moyenne extends Fonctions{ | |
6 | + | |
7 | + | |
8 | + public String toString(){ | |
9 | + | |
10 | + return "MOYENNE(" + listCases.stream() | |
11 | + .map( n -> n.getId() ) | |
12 | + .collect( Collectors.joining( "," ) ) | |
13 | + +")"; | |
14 | + } | |
15 | + | |
16 | + public String getFormuleDeveloppe(){ | |
17 | + | |
18 | + return ""; | |
19 | + } | |
20 | + | |
21 | + public double eval() { | |
22 | + | |
23 | + double val=0; | |
24 | + | |
25 | + try{ | |
26 | + for(int i=0; i<listCases.size(); i++) | |
27 | + val += listCases.get(i).getValeur(); | |
28 | + | |
29 | + return val/ listCases.size(); | |
30 | + } | |
31 | + catch(ArithmeticException ex){} | |
32 | + } | |
33 | +} | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +package noyau; | |
2 | + | |
3 | +public class Multiplication extends OperationBinaire{ | |
4 | + | |
5 | + Multiplication(Case g,Case d){ | |
6 | + gauche=g; | |
7 | + droite=d; | |
8 | + } | |
9 | + | |
10 | + | |
11 | + public double eval() { | |
12 | + | |
13 | + if (!creerCycle(gauche) && !creerCycle(droite)) | |
14 | + return gauche.getValeur() * droite.getValeur(); | |
15 | + } | |
16 | + | |
17 | + | |
18 | + public String toString(){ | |
19 | + | |
20 | + return gauche.getId() +" * " + droite.getId() ; | |
21 | + } | |
22 | + | |
23 | + | |
24 | + | |
25 | + public String getFormuleDeveloppe(){ | |
26 | + | |
27 | + return ""; | |
28 | + } | |
29 | + | |
30 | +} | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +package noyau; | |
2 | + | |
3 | +import java.util.ArrayList; | |
4 | + | |
5 | +abstract public class OperationBinaire extends Formule { | |
6 | + | |
7 | + Case droite; | |
8 | + Case gauche; | |
9 | + | |
10 | + abstract public String getFormuleDeveloppe(); | |
11 | + | |
12 | + | |
13 | + | |
14 | + public boolean creerCycle(Case uneCase){ | |
15 | + | |
16 | + //if (!listePlage.contains(uneCase) && uneCase.utiliseDans.size()==0) | |
17 | + return false; | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + | |
23 | + } | |
24 | +} | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +package noyau; | |
2 | + | |
3 | +import java.util.*; | |
4 | +import java.util.stream.Collectors; | |
5 | + | |
6 | +public class Somme extends Fonctions{ | |
7 | + | |
8 | + public String toString(){ | |
9 | + | |
10 | + return "SOMME(" + listCases.stream() | |
11 | + .map( n -> n.getId() ) | |
12 | + .collect( Collectors.joining( "," ) ) | |
13 | + +")"; | |
14 | + } | |
15 | + | |
16 | + public String getFormuleDeveloppe(){ | |
17 | + | |
18 | + return ""; | |
19 | + } | |
20 | + | |
21 | + public double eval() { | |
22 | + | |
23 | + double val=0; | |
24 | + | |
25 | + if (listCases.size() != 0) | |
26 | + for(int i=0; i<listCases.size(); i++) | |
27 | + val += listCases.get(i).getValeur(); | |
28 | + | |
29 | + return val; | |
30 | + } | |
31 | +} | ... | ... |
... | ... | @@ -0,0 +1,32 @@ |
1 | +package noyau; | |
2 | + | |
3 | +public class Soustraction extends OperationBinaire{ | |
4 | + | |
5 | + Soustraction(Case g,Case d){ | |
6 | + gauche=g; | |
7 | + droite=d; | |
8 | + } | |
9 | + | |
10 | + | |
11 | + | |
12 | + public double eval() { | |
13 | + | |
14 | + if (!creerCycle(gauche) && !creerCycle(droite)) | |
15 | + return gauche.getValeur() - droite.getValeur(); | |
16 | + } | |
17 | + | |
18 | + | |
19 | + | |
20 | + | |
21 | + public String toString(){ | |
22 | + | |
23 | + return gauche.getId() +" - " + droite.getId() ; | |
24 | + } | |
25 | + | |
26 | + | |
27 | + public String getFormuleDeveloppe(){ | |
28 | + | |
29 | + return ""; | |
30 | + } | |
31 | + | |
32 | +} | ... | ... |