ObjectiveIn this lab, you will gain experience programming using two-dimensional arrays. In particular, you will be developing a Map class, which will print out a map of the universe in our game. If you need a refresher on 2-D arrays, you may want to look over the lecture notes on arrays, starting at slide 67. FilesThere are a number files that you need to download for this lab.
To run this lab, execute the Game.java file. This file creates a default universe, and prints it out -- it is not an interactive game for this lab. As always, the documentation for the various parts of this project, including the Map class, can be found here. Map class overviewIn this lab, you will be developing a Map class, which will print out a map of the universe. Note that the 'universe' is the world for your game -- whether it be UVa grounds, the US, the world, or a solar system. A sample output of the functionality of the Map class is shown below. The Game.java file that is provided will produce slightly different input , which is shown below. Printing Universe - - - - - - - - - 1 - - - - - - - - - - - - - - - - - 2 - - - 3 - - - - - - - - - - - - - - - - - - 4 - 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - The valid destinations are: 1: Geminorum (your location) 2: Ursae Majoris 3: Andromedae 4: Orionis 5: Cygni Note that the Unvierse has a height of 10 and a width of 8. If yours is reversed (meaning yours has a height of 8 and a width of 10), then something is wrong. There are three methods that you will need to develop for this lab, which are described in more detail below. One prints the grid (the top half of the output shown above), the second prints the list (the bottom half of the output shown above), and the third ties the two together. You will notice that the locations have a very specific numbering. The numbers start at 1, and increase left-to-right, then top-to-bottom. In other words, the numbering goes through each row in order, giving increasing values to the locations. This ordering is used in both methods, and it is how the methods know which location has what number. Universe classThe Universe class will be developed in HW J8. However, we have provided you with a Universe.java class so that you can complete this lab. Note that the code that we provide is NOT the code you need to submit for HW J8 -- it was designed to work for this lab, but works in a very different manner than is required for HW J8 (notice that there are no 2-D arrays in the Universe.java for this lab). Whenever we specify the size of our universe, we are going to specify the row first, followed by the column. Thus, in the universe above, the coordinates of Orionis (location number 4) are (6,2), not (2,6). Also note that the top left-most coordinate is (0,0). So Geminorum (location 1) is at coordinates (1,1). The Universe class will provide a number of methods that you can use -- the full list can be found here. The Universe class that we provide with this lab only has four of those methods implemented, as this lab uses only those methods:
Map classThere are three methods that you need to develop for this lab. All methods are to be public and static. It is recommended that you develop them in the order specified. The Game.java file is set up to allow you to test each of the individual methods as you develop them. Note that there are no fields in this class.
TestingTo run this lab, execute the Game.java file. This file creates a default universe, and prints it out -- it is not an interactive game for this lab. As always, the documentation for the various parts of this project, including the Map class, can be found here. The output from an execution run is shown below. Note that it tests all three of the methods. Your location names will probably differ. Testing of the Map class ---------------------------------------- Test of printGrid(): - - - - - - - - - 1 - - - - - - - - - - - - - - - - - 2 - - - 3 - - - - - - - - - - - - - - - - - - 4 - 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - ---------------------------------------- Test of printLocations(): The valid destinations are: 1: Geminorum (your location) 2: Ursae Majoris 3: Andromedae 4: Orionis 5: Cygni ---------------------------------------- Test of printMap(): Printing Universe - - - - - - - - - 1 - - - - - - - - - - - - - - - - - 2 - - - 3 - - - - - - - - - - - - - - - - - - 4 - 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - The valid destinations are: 1: Geminorum (your location) 2: Ursae Majoris 3: Andromedae 4: Orionis 5: Cygni SubmissionWhen you are finished, you just need to submit the Map.java file. Note that there are a few more questions that are asked for this lab submission. As the the other java files were not modified, they do not need to be submitted. If you finish earlyIf you finish early, you can work on HW J8. |