CMPSCI 187: Programming With Data Structures

David Mix Barrington

Fall, 2012

Programming Project #4: A Survey of Continents

Originally posted 25 October 2012, due at 11:59 p.m. EDT on Monday 5 November 2012, by placing .java files in a subdirectory of your cs187 directory on your edlab account, called proj4. For more information on accessing the edlab, see here or ask in discussion section.

Goals of this project:

  1. Write a program using queues to solve a search problem.
  2. Write a program using lists to determine the high, low, and average values of several parameters of randomly generated objects.

Questions and answers about this project are collected here.

In Project 3, you extended the Grid class from Section 4.4 of DJW to make a MapGrid class supporting a method continentMap, which returns a map of the grid indicating to which continent each square belongs.

That project originally contained two other tasks, to create a method capitalMap, which returns a map with squares assigned to continents and a centrally located capital square chosen for each map, and to create a method continentTable, which returns a formatted table with the name, capital location, and size of each continent. Here the "size" means the distance from the capital to the farthest square on the continent, measured by paths of north-east-south-west steps using only land squares. The capital was chosen to minimize this distance.

Your first two tasks for this project are to complete those two remaining tasks from Project 3, which you can read about there. Please include copies of all the classes you need in your proj4 directory so we may test your code there.

The remaining tasks will involve the use of lists. What I want is to run some experiments on the range of MapGrid objects we can get by varying the initial seed. Here's the facts I want:

  1. For a MapGrid with 10 rows, 40 columns, and a percentage of 30, how many continents do we get? You should have methods highNumConts, lowNumConts, and AveNumConts, each in the MapGrid class. The first two each return a MapGrid object and the third returns a double value. They each take five int parameters: rows, cols, percentage, lowSeed, and highSeed. The MapGrid objects they return are taken from the MapGrids with that many rows, that many columns, that percentage, and seeds in the range from lowSeed to highSeed, inclusive. The three methods give the MapGrid with the most continents, the MapGrid with the fewest continents, and the average number of continents for that set of MapGrids.
  2. Repeat for the three methods highLargestCont, lowLargestCont, and AveLargestCont, where "largestCont" refers to the size (as defined above) of the largest continent in the grid. Again the first two methods each return a MapGrid object and the third returns a double value.
  3. (suggested by a student in lecture) If we keep the rows at 10 and the columns at 40 but vary the percentage, the two statistics aveNumConts and aveLargestCont vary as well. At percentage 0, both are 0. The number of continents goes up at the start and then back down to 1 by percentage 100. A student asserted in lecture that the peak came at percentage 30 -- is this exactly true? The size of the largest continent goes up, and is going to be about 25 at the end. But at percentages like 90, where there will probably be one continent with a bunch of lakes in it, is it ever higher than the percentage 100 value?

    Your third task is to write a method percentageTable that takes parameters rows, cols, lowSeed, and highSeed and lists the values of those two methods for all percentages from 0 through 100, using the seeds in the given range.

The natural way to find the low and high MapGrids, and to compute the average, is to put all the MapGrids in a list of MapGrids, then traverse the list with an iterator (or a DJW reset/getNext loop) processing each element to get the final values.

You should put your classes in your EdLab space, in a directory called "cs187/proj4", and test the behavior with a main method or a driver class. (We will test the code with our own driver class.)

If you create your code within Eclipse (which we encourage but don't require), you will want to ignore the warning message that says "The use of the default package is discouraged". Bear in mind that if you make the mistake of declaring your class in a package, our driver class will not see it (since it will not be in a package) and we won't be able to test your code.

Last modified 25 October 2012