Special Lab 7

In this lab, you will use a small part of GridWorld to practice writing loops.

Consider the following program:

import info.gridworld.actor.Rock;
import info.gridworld.grid.Location;
import info.gridworld.grid.UnboundedGrid;
import info.gridworld.world.World;

public class Rocks
   public static void main(String[] args)
      UnboundedGrid<Rock> gr = new UnboundedGrid<Rock>();
      World<Rock> world = new World<Rock>(gr);
      final int LENGTH = 11;
      for (int i = 1; i <= LENGTH; i++)
         for (int j = 1; j <= LENGTH; j++)
               gr.put(new Location(i, j), new Rock());      

(Remember to add gridworld.jar to your project/class path when you compile and run this program.)

1. What is the result of running this program?

2. Write a program that produces a pile of rocks that is shaped like a triangle, like in section 7.3 of your textbook. What is your modified program? (Call it Rocks2)


3. Modify this program so that the tip of the triangle is in the middle, like this:


What is your program? (Call it Pyramid)

Note: You may introduce additional loops if you like.

4. Modify this program so that it produces a diamond shape, like this:


What is your program? (Call it Diamond.)

5. Write a program that only shows the outline of the diamond, like this:


What is your program? (Call it DiamondOutline)

Email me the answers. Subject line: CS46A Special Lab 7 your name/your buddy's name