GARC923

L3A1 Carlos Garcia

Oct 20th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package Lesson3;
  2.  
  3. import kareltherobot.UrRobot;
  4. import kareltherobot.World;
  5.  
  6. import java.awt.*;
  7. import java.beans.BeanProperty;
  8. import java.sql.Wrapper;
  9. import java.util.Scanner;
  10.  
  11.  
  12. public class Activity1 extends UrRobot {
  13.     public Activity1(int street , int avenue , Direction direction , int beeperCount){
  14.         super(street, avenue, direction, beeperCount, Color.PINK);
  15.     }
  16.  
  17.  
  18.  
  19.     public static void main(String[] args) {
  20.         World.setDelay(50);
  21.         World.setVisible();
  22.         World.setBeeperColor(Color.blue);
  23.         World.setSize(10,10);
  24.         World.showSpeedControl(true);
  25.  
  26.         Activity1 zgod = new Activity1(1,1,North,-1);
  27.  
  28.         zgod.shuttleRun();
  29.     }
  30.  
  31.    /**
  32.     * Function for having the robot go up or down in a set
  33.     * @return void
  34.     * */
  35.     public void upDown(){
  36.         move();
  37.         move();
  38.         move();
  39.         turnLeft();
  40.         turnLeft();
  41.     }
  42.  
  43.     /**
  44.      * Function for having the robot turn right
  45.      * @return void
  46.      * */
  47.     public void turnRight(){
  48.         turnLeft();
  49.         turnLeft();
  50.         turnLeft();
  51.     }
  52.  
  53.     /**
  54.      * Function for doing the reps in a set
  55.      * @param reps counts the number of reps
  56.      * @return void
  57.      * */
  58.     public void rep(int reps){
  59.         for (int i = 0; i < reps; i++) { // loop to make the robot go up and down one time for each rep
  60.             upDown();
  61.             putBeeper();
  62.             upDown();
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Function for executing the shuttle run
  68.      * @return void
  69.      * */
  70.     public void shuttleRun(){
  71.         Scanner scanner = new Scanner(System.in);  // Create a Scanner object
  72.         System.out.println("How many sets do you want ZGOD to do?");
  73.         int sets = scanner.nextInt(); //creates int to save the number of sets
  74.         if (sets > 10){
  75.             World.setSize(10,sets); // sets the number of avenues to however many sets the user wants the robot to do if the number is greater than 10
  76.         }
  77.         System.out.println("How many reps do you want ZGOD to do for each set?");
  78.         int reps = scanner.nextInt(); // int for storing the number of reps that the user wants the robot to do
  79.  
  80.         for (int i = 0; i < sets; i++) { // loop that runs the reps as many times as there are sets
  81.             rep(reps);
  82.             turnRight();
  83.             move();
  84.             turnLeft();
  85.         }
  86.     }
  87.  
  88.  
  89. }
  90.  
Add Comment
Please, Sign In to add comment