Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. @Override
  2. public void completeUpdate(Instruction instruction) {
  3.  
  4. PrintStream printStream = new PrintStream(out);
  5.  
  6. switch (instruction){
  7. case Read:
  8. Scanner scanner = new Scanner(in);
  9. if(!scanner.nextLine().equals("\n")){
  10. printStream.print("Illegal Input: Insert only one character!");
  11. }
  12. scanner.close();
  13. break;
  14. case Write:
  15. printStream.print("\n");
  16. break;
  17. }
  18.  
  19. }
  20.  
  21. @Override
  22. public void run() {
  23.  
  24. Interpreter interpreter = new MyInterpreter(util.buildPipe(in), util.buildPipe(out));
  25. PrintStream printStream = new PrintStream(out);
  26. Scanner scanner = new Scanner(in);
  27.  
  28. printStream.print("--------------------------\n Interactive Ook! Shell\n--------------------------\n");
  29.  
  30. if(scanner.nextLine().equals("Bananas")){
  31. printStream.print("Yippee!");
  32. }else if(scanner.nextLine().equals("Monkey")){
  33. printStream.print("Ouch!");
  34. }else{
  35.  
  36. Optional<Instruction> optionalInstruction = parseLine(scanner.nextLine());
  37.  
  38. if(optionalInstruction.isPresent()){
  39.  
  40. interpreter.loadInstruction(optionalInstruction.get());
  41. if(scanner.hasNext()){
  42. Optional<Instruction> o = parseLine(scanner.nextLine());
  43. this.prepareUpdate(o.get());
  44. interpreter.update();
  45. this.completeUpdate(o.get());
  46. }
  47.  
  48. }else{
  49. printStream.print("Invalid instruction: " + optionalInstruction.get().name());
  50. }
  51.  
  52. }
  53.  
  54. scanner.close();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement