Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. class CalculatorInput{
  5. BufferedReader stream;
  6. CalculatorEngine engine;
  7.  
  8. CalculatorInput(CalculatorEngine e){
  9. InputStreamReader input = new InputStreamReader(System.in);
  10. stream = new BufferedReader(input);
  11. engine = e;
  12. }
  13.  
  14. void run() throws Exception{
  15. System.out.print("calculadora \n");
  16. for(;;){
  17. System.out.print("[" + engine.display() + "]");
  18. String m = stream.readLine();
  19. if(m == null) break;
  20. if(m.length() > 0){
  21. char c = m.charAt(0);
  22. if (c == '+')
  23. engine.add();
  24. else if (c == '-')
  25. engine.subtract();
  26. else if (c == '*')
  27. engine.multiply();
  28. else if (c == '/')
  29. engine.divide();
  30. else if (c >= '0' && c <= '9')
  31. engine.digit(c - '0');
  32. else if (c == '=')
  33. engine.compute();
  34. else if (c == 'c' || c == 'C')
  35. engine.clear();
  36. }
  37. }
  38. }
  39. public static void main (String arg[]) throws Exception {
  40. CalculatorEngine e = new CalculatorEngine();
  41. CalculatorInput x = new CalculatorInput(e);
  42. x.run();
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement