From: Jérôme Benoit Date: Fri, 13 Apr 2018 09:49:02 +0000 (+0200) Subject: exo6: add constructor and some sanity checks to Chiffre and Variable X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c9ca22835b3ec5dd779b4e8ffae46ceb829d4b1a;p=Project_POO.git exo6: add constructor and some sanity checks to Chiffre and Variable classes. Signed-off-by: Jérôme Benoit --- diff --git a/exo6/Chiffre.java b/exo6/Chiffre.java index 1a0c3cb..be6f881 100644 --- a/exo6/Chiffre.java +++ b/exo6/Chiffre.java @@ -1,7 +1,20 @@ class Chiffre extends Facteur { + Character c; - public boolean evaluer() { - return true; + Chiffre(Character c) throws NotCharacterException { + //TODO?: remove extragenous whitespace + if (Character.isLetterOrDigit(c)) { + this.c = c; + } else { + throw new NotCharacterException(c + " is not a character type"); + } + } + + private boolean isChiffre() { + return Character.isDigit(c); + } + public double evaluer() { + return 0.0; } } diff --git a/exo6/Expression.java b/exo6/Expression.java index d89d26a..dc8a855 100644 --- a/exo6/Expression.java +++ b/exo6/Expression.java @@ -1,5 +1,5 @@ public abstract class Expression { - - abstract boolean evaluer(); + + abstract double evaluer(); } diff --git a/exo6/Makefile b/exo6/Makefile index 06d4e73..d8399cf 100644 --- a/exo6/Makefile +++ b/exo6/Makefile @@ -46,6 +46,7 @@ JVM = java # NAME = Camilo Juan CLASSES = \ + NotCharacterException.java \ Expression.java \ Terme.java \ Opadd.java \ diff --git a/exo6/NotCharacterException.java b/exo6/NotCharacterException.java new file mode 100644 index 0000000..1f9b80c --- /dev/null +++ b/exo6/NotCharacterException.java @@ -0,0 +1,24 @@ + +public class NotCharacterException extends Exception { + + public NotCharacterException() { + super(); + // TODO Auto-generated constructor stub + } + + public NotCharacterException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public NotCharacterException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public NotCharacterException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + +} diff --git a/exo6/Opdiv.java b/exo6/Opdiv.java index 6ac4715..99a3883 100644 --- a/exo6/Opdiv.java +++ b/exo6/Opdiv.java @@ -1,7 +1,7 @@ class Opdiv extends Opmul { - public boolean evaluer() { - return true; + public double evaluer() { + return 0.0; } } diff --git a/exo6/Opminus.java b/exo6/Opminus.java index c200b74..d33cd17 100644 --- a/exo6/Opminus.java +++ b/exo6/Opminus.java @@ -1,7 +1,7 @@ class Opminus extends Opadd { - public boolean evaluer() { - return true; + public double evaluer() { + return 0.0; } } diff --git a/exo6/Opmulti.java b/exo6/Opmulti.java index c2bf12a..596015f 100644 --- a/exo6/Opmulti.java +++ b/exo6/Opmulti.java @@ -1,7 +1,7 @@ class Opmulti extends Opmul { - public boolean evaluer() { - return true; + public double evaluer() { + return 0.0; } } diff --git a/exo6/Opplus.java b/exo6/Opplus.java index 3049f60..0bd4bfa 100644 --- a/exo6/Opplus.java +++ b/exo6/Opplus.java @@ -1,7 +1,7 @@ class Opplus extends Opadd { - public boolean evaluer() { - return true; - } + public double evaluer() { + return 0.0; + } } diff --git a/exo6/Parenthese.java b/exo6/Parenthese.java index 067fcdd..2be283b 100644 --- a/exo6/Parenthese.java +++ b/exo6/Parenthese.java @@ -1,7 +1,7 @@ class Parenthese extends Facteur { - public boolean evaluer() { - return true; - } + public double evaluer() { + return 0.0; + } } diff --git a/exo6/Variable.java b/exo6/Variable.java index d023c98..30b7830 100644 --- a/exo6/Variable.java +++ b/exo6/Variable.java @@ -1,7 +1,24 @@ +import java.util.TreeMap; class Variable extends Terme { + TreeMap v; - public boolean evaluer() { - return true; + Variable(Character c) throws NotCharacterException { + v = new TreeMap(); + //TODO?: remove extragenous whitespace + if (Character.isLetterOrDigit(c)) { + v.put(c, 0.0); // we suppose the default variable value is 0 + } else { + throw new NotCharacterException(c + " is not a character type"); + } + } + + private boolean isVariable() { + //FIXME: this cover more than latin alphabet + return Character.isLetter(v.firstKey()); + } + + public double evaluer() { + return 0.0; } } diff --git a/exo6/design_arithmetic.uxf b/exo6/design_arithmetic.uxf index 9cf878c..6e69bb0 100644 --- a/exo6/design_arithmetic.uxf +++ b/exo6/design_arithmetic.uxf @@ -8,10 +8,10 @@ 100 60 - Expression + /Expression/ -- -- -/+evaluer()/ +/+evaluer():/ @@ -23,7 +23,7 @@ 100 30 - Terme + /Terme/ @@ -34,7 +34,7 @@ 100 30 - Op-add + /Op-add/ @@ -45,7 +45,7 @@ 100 30 - Facteur + /Facteur/ @@ -70,7 +70,7 @@ 100 30 - Op-mul + /Op-mul/