Advertisement
ChiaraMariee

Untitled

Apr 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. package business_logic;
  2.  
  3. import javax.script.ScriptEngine;
  4. import javax.script.ScriptEngineManager;
  5. import javax.script.ScriptException;
  6.  
  7. public class JythonParser {
  8.  
  9. public JythonParser() {
  10.  
  11. }
  12.  
  13. // Diese Methode wird von der GUI aufgerufen
  14. public double parseCommand(String command) throws ScriptException {
  15. ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
  16. engine.eval("import sys");
  17. engine.put("calculation", command);
  18. // engine.eval("print calculation");
  19. engine.eval("calculation = eval(calculation)");
  20. // engine.eval("print calculation");
  21. String result = engine.get("calculation").toString();
  22. return Double.parseDouble(result);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement