Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class gironx_BugSimulation {
  5. public static void main(String [] args) {
  6. gironx_Bug bug = new gironx_Bug();
  7.  
  8. Scanner input = new Scanner(System.in);
  9. System.out.println("Enter an initial position.");
  10. String dir = "right";
  11. bug.setDirection(dir);
  12. int pos = input.nextInt();
  13. bug.setPosition(pos);
  14. System.out.println("The bug has been created facing right at the position: " + pos);
  15. System.out.println("How many moves do you wish to make?");
  16. int NumMov = input.nextInt();
  17. for(int iteration = 0; iteration < NumMov; iteration++) {
  18. System.out.println("The bug has moved");
  19. pos = bug.Move();
  20. }
  21. System.out.println("The new position for the bug is: " + pos + " It is facing " + dir);
  22.  
  23. System.out.println("How many time do you wish to turn?");
  24. int TurMov = input.nextInt();
  25. for(int iteration = 0; iteration < TurMov; iteration++) {
  26.  
  27. dir = bug.Turn();
  28.  
  29. System.out.println("The bug has turned");
  30. }
  31.  
  32. System.out.println("The new direction the bug is facing is: " + dir + " and its position is: " + pos);
  33. System.out.println("How many time do you wish to move? ");
  34.  
  35. int NewMov = input.nextInt();
  36.  
  37. for(int iteration = 0; iteration < NewMov; iteration++) {
  38.  
  39. pos = bug.Move();
  40.  
  41. System.out.println("The bug has moved.");
  42. }
  43.  
  44. System.out.println("The bug's final position is " + pos + " and the direction it is facing is: " + dir);
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement