Random Tasks

 

The purpose of these tasks is to allow you to familiarize yourself with the java.util.Random class and some of the methods it offers.

  1. To prepare, create a Robots project called RandomTasks, and declare a class field as follows,

    	private static Random random = new Random();

    You'll use the random object to facilitate the subsequent requests.

  2. Consider the nextInt(n) method. Create a City with (0,0) as the first visible street and avenue, 5 streets, and a random number of avenues between 0 and 5 (inclusive) avenues. Run your code a few times to confirm empirically that it is working. Were there any issues ?
  3. Create a City with (0,0) as the first visible street and avenue, 5 streets and anywhere between 1 and 5 (inclusive) avenues. Confirm empirically.
  4. Create a City using the default constructor and add a RobotSE object to your City that appears at a random visible intersection. Confirm.
  5. Modify your RobotSE constructor to have the object initially appear and an even street address and an odd avenue address. Confirm.
  6. Modify your RobotSE constructor from the previous step to start with a random number of Things in its backpack that is a multiple of 5 up to and including 35. Turn on your city's ability to show the Thing counts and have the RobotSE object put all things to confirm.

More to come...