Mise en place de la calculatrice utilisable depuis le chat : précéder l'expression mathématique par un =

This commit is contained in:
2014-12-26 13:44:49 -05:00
parent 6f05cf681f
commit 5990672dfb
3 changed files with 139 additions and 15 deletions

View File

@@ -449,21 +449,12 @@ public class JArithmeticInterpreter {
//.................................................................................... Write_Tree
public String writeTree() {
StringBuffer sb = new StringBuffer();
writeTree(sb);
return sb.toString();
}
private void writeTree(StringBuffer string) {
boolean parenthese=false;
switch(mOperator) {
case 0:
string.append(mValue);
string.append(StringUtil.formatDouble(mValue));
break;
case 1:
fg.writeTree(string);
@@ -740,7 +731,7 @@ public class JArithmeticInterpreter {
}
public static double getResultFromExpression(String expr)
public static double getResultFromExpression(String expr, StringBuffer writeTree)
{
StringBuffer input = new StringBuffer(expr);
@@ -749,16 +740,29 @@ public class JArithmeticInterpreter {
if (jai==null)
throw new IllegalArgumentException("Le calcul passé en paramètre est invalide");
if (writeTree != null)
{
writeTree.setLength(0);
jai.writeTree(writeTree);
}
return jai.computeTree();
}
/*
public static double getResultFromExpression(String expr)
{
return getResultFromExpression(expr, null);
}
public static void main(String args[]) {
String disp_res = StringUtil.formatDouble(JArithmeticInterpreter.getResultFromExpression("1245.25*2"));
StringBuffer b = new StringBuffer(0);
String disp_res = StringUtil.formatDouble(JArithmeticInterpreter.getResultFromExpression("1245.25*2", b));
System.out.println(disp_res);
} //*/
System.out.println(b);
} // */
}