Files
GTSchoolShit/CS1322/p1/World.java
2025-06-07 01:59:34 -04:00

237 lines
6.1 KiB
Java

/**
* <PRE>
* World.java
*
* Revisions: 1.0 Sep. 02, 2002
* Created the World class
* 1.1 Sep. 03, 2002
* Compiled, Tested, Run
* 1.2 Sep. 05, 2002
* Commented (late thanks to failed winXP SP1)
* 1.3 Sep. 16, 2002
* Added omit nulls, gg Outlook Express for not updating...
* </PRE>
*
* Collaboration Statement:
* I worked on the homework assignment alone, using only
* course materials.
*
* Created with JCreatorLE, some indents are off when viewed through notepad
* or EMACS
*
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
* @version Version 1.3, Sep. 16, 2002
*/
public class World {
private City[][] map;
public static final boolean bDebug = false;
////////////
//Modifier//
////////////
public void setWorld(City[][] twoDArray){
map = twoDArray;
}
///////////
//Methods//
///////////
/**
*Find city at given latitude and longitude
*@param lat, the latitude
*@param lon, the longitude
*@return the City, or NULL if none exists
*/
public City getCityAt(int lat, int lon){
City temp = new City();
if(map[lon][lat] != null){
temp = map[lon][lat];
return temp;
}
else {
return null;
}
}//end of getCityAt(int lat, int lon)
/**
*Find cities at given latitude
*@param lat, the latitude
*@return the Cities at the given latitude
*/
public City[] getCititesAtLatitude(int lat){
//omit nulls without destroying map
int nulls = 0;
for(int i=0; i<map.length; i++){
if(map[i][lat] == null){
nulls++;
}
}
//create temp array for latitude
City[] array = new City[map.length-nulls];
int current = 0;
if(bDebug){
System.out.println("Begin Iteration getCititesAtLat");
}
for(int i=0; i<map.length; i++){
if(map[i][lat] != null){
array[current] = map[i][lat];
current++;
}
}
/////////////////
if(bDebug){
System.out.println("End Iteration getCititesAtLat");
}
return array;
}//end of getCititesAtLatitude, yes its misspelled in the .nfo
/**
*Find cities at given longitude
*@param lon, the longitude
*@return the Cities at the given longitude
*/
public City[] getCititesAtLongitude(int lon){
//omit nulls without destroying map
int nulls = 0;
for(int i=0; i<map[lon].length; i++){
if(map[lon][i] == null){
nulls++;
}
}
//create temp array for longitude
City[] array = new City[map[lon].length-nulls];
int current = 0;
if(bDebug){
System.out.println("Begin Iteration getCititesAtLon");
}
for(int i=0; i<map[lon].length; i++){
if(map[lon][i] != null){
array[current] = map[lon][i];
current++;
}
}
if(bDebug){
System.out.println("End Iteration getCititesAtLon");
}
return array;
}//end of getCititesAtLongitude
/**
* Debugging main for class World.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
City[][] twoDArray = new City[16][6];
//create the 8 cities, 2 per row....mwahahaha...
//city #1
twoDArray[0][0] = new City();
twoDArray[0][0].setName("Weston");
twoDArray[0][0].setCountry("United States");
twoDArray[0][0].setPopulation(4332);
if(bDebug){
System.out.println("works");
System.out.flush();
}
//city #2
twoDArray[0][3] = new City();
twoDArray[0][3].setName("Nerd Land");
twoDArray[0][3].setCountry("Everquest on WINEX");
twoDArray[0][3].setPopulation(4511); //too many, thats the population
//city #3
twoDArray[1][2] = new City();
twoDArray[1][2].setName("Atlanta");
twoDArray[1][2].setCountry("Georgia");
twoDArray[1][2].setPopulation(3304000); //as of 2000, yes I checked
//city #4
twoDArray[1][3] = new City();
twoDArray[1][3].setName("Vulcan");
twoDArray[1][3].setCountry("Nerdtopia"); //actually, I like Star Trek :|
twoDArray[1][3].setPopulation(5252); //as of 2001
//city #5
twoDArray[2][0] = new City();
twoDArray[2][0].setName("Leene Square");
twoDArray[2][0].setCountry("Chrono Trigger Land");
twoDArray[2][0].setPopulation(21); //probably about right ;)
//city #6
twoDArray[2][2] = new City();
twoDArray[2][2].setName("Doom");
twoDArray[2][2].setCountry("When Id was good");
twoDArray[2][2].setPopulation(3); //number of classics Id made
//city #7
twoDArray[3][1] = new City();
twoDArray[3][1].setName("John Romero");
twoDArray[3][1].setCountry("Ion Storm"); //hehe, not anymore :(
twoDArray[3][1].setPopulation(1);
//city #8
twoDArray[3][3] = new City();
twoDArray[3][3].setName("Zelda");
twoDArray[3][3].setCountry("Miyamato's Best");
twoDArray[3][3].setPopulation(4); //number of classics he made
/*************************************************************/
World world = new World();
world.setWorld(twoDArray);
System.out.println(world.getCityAt(0,0));
System.out.println(world.getCityAt(2,1));
//////////
System.out.println("\n END TEST GETCITY START LAT\n");
//////////
//test latitude
City[] latitude;
latitude = world.getCititesAtLatitude(3);
for(int i = 0; i<latitude.length; i++){
System.out.println(latitude[i]);
}
//////////
System.out.println("\n END TEST LAT START LON\n");
//////////
//test longitude
City[] longitude;
longitude = world.getCititesAtLongitude(2);
for(int i = 0; i<longitude.length; i++){
System.out.println(longitude[i]);
}
}// end of main(String[] args)
}// end of class World