X-Git-Url: https://git.piment-noir.org/?p=Project_POO.git;a=blobdiff_plain;f=exo6%2FVariable.java;h=6a85fbbc94704a433136a32fb021525fb05eb3b8;hp=30b7830a2b239517fcd0041c973229fe40c304ae;hb=bd83b176f508492a46cc4f76998721c30a22d291;hpb=c9ca22835b3ec5dd779b4e8ffae46ceb829d4b1a diff --git a/exo6/Variable.java b/exo6/Variable.java index 30b7830..6a85fbb 100644 --- a/exo6/Variable.java +++ b/exo6/Variable.java @@ -1,24 +1,38 @@ import java.util.TreeMap; +import java.util.Map.Entry; class Variable extends Terme { - TreeMap v; + //TODO: TreeMap might look overkill + TreeMap v; - 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"); + Variable() { + v = new TreeMap(); + fill(-5.0, 5.0, 0.25); + } + + /** + * Fill the variable with a discret set of double values + * @param start starting double value + * @param end ending double value + * @param step looping step + */ + private void fill(double start, double end, double step) { + int i = 0; + for (double d = start; d <= end; d = d + step) { + v.put(i, d); + i++; } } - private boolean isVariable() { - //FIXME: this cover more than latin alphabet - return Character.isLetter(v.firstKey()); + public Entry getFirstEntry() { + return v.firstEntry(); + } + + public Integer size() { + return v.size(); } public double evaluer() { - return 0.0; + return v.pollFirstEntry().getValue(); } }