//**add your header information here**
//World class: Complete the incomplete methods, and do not change any of the
//  syntax (besides variable names) for what is provided for you.

public class World {
	
	///////////////////
	//class variables:
	static final String [] positions = {"north", "south", "east", "west"};
	//used when checking neighboring positions
	
	//////////////////////
	//instance variables:
	String name;//name of the world
	private City [] cities; //an array of City objects
	//other variables up to designer
	
	//////////////////////////////////////////////////////////////////////////
	//constructors:
	public World(String name){
		//constructor for only a name: should create an array of size 0

	}
	public World(String name, City [] cities){
		//creates a world with the cities passed in

	}
	
	//////////////////////////////////////////////////////////////////////////
	//instance methods:
	public City createCity(String cityName){
		//creates a city with no neighbors, with name given.
		//**this method is completed:
		return new City(cityName);
	}
	
	public void insertCity(City newCity){
		//inserts a city into the world if it does not already exist
		//**this method is completed:
		City [] newCities = new City[this.cities.length + 1];
		for (int i = 0; i < this.cities.length; i++){
		//check if city exists
			if (this.cities[i].equals(newCity))
				//city exists,just return (newCities is lost)
				return;
			newCities[i] = this.cities[i];
		}
		newCities[this.cities.length] = newCity;
		this.cities = newCities; //update instance variable
	}
	
	public City createAndInsertCity(String cityName){
		//creates a city and inserts it into the array
		//returns the city as well

	}
	
	public void removeCity(String cityName){
		//removes a city from the world
		//shifts all elements of the cities array to the left to fill in
		//hole (create a new array which is shifted as such)
		//Remember to remove the city from being a neighbor of any city
		//(If a city has this city as a neighbor, then set it’s neighbor
		//for that position to be null)

	}
	
	public City getCity (String cityName){
		//returns the City with name cityName (must search for city in the array)
		//if the city does not exist, it returns null
 
 	}
	
	public String toString(){
		//should indicate all cities
			
	}
	
	////////////////////////////////////////////////////////////////////////
	//Class Methods: 
	
	//a main method to test the code with will be provided
	public static void main (String [] args){
		//cities used in test:    0           1       2         3                4              5          6            7         8
		String [] cityNames = {"Orlando", "London", "Tokyo", "San Fransisco", "Nowhereville", "Atlanta", "Charlotte", "Miami", "Tampa"};
		
		World w1 = new World("Earth");
		//create and insert cities:
		for (int i = 0; i < cityNames.length; i++)
			w1.createAndInsertCity(cityNames[i]);
			
		//set up and test neighbors and toString methods:
		City orl = w1.getCity("Orlando");
		System.out.println("Orlando before Neighbors: \n" + orl + "\n- - - - - - -\n");
		
		orl.setNeighbor(w1.getCity("Atlanta"), "north");
		w1.getCity("Atlanta").setNeighbor(orl, "south");
		
		orl.setNeighbor(w1.getCity("Tampa"), "west");
		w1.getCity("Tampa").setNeighbor(orl, "east");
		
		orl.setNeighbor(w1.getCity("Miami"), "south");
		w1.getCity("Miami").setNeighbor(orl, "north");
		System.out.println("Orlando after Neighbors: \n" + orl + "\n- - - - - - -\n");
		
		w1.getCity("Charlotte").setNeighbor(w1.getCity("Atlanta"), "south");
		w1.getCity("Atlanta").setNeighbor(w1.getCity("Charlotte"), "north");
		
		w1.getCity("San Fransisco").setNeighbor(w1.getCity("Nowhereville"), "west");
		w1.getCity("Nowhereville").setNeighbor(w1.getCity("San Fransisco"), "east");
		
		w1.getCity("Tokyo").setNeighbor(w1.getCity("Nowhereville"), "south");
		w1.getCity("Nowhereville").setNeighbor(w1.getCity("Tokyo"), "north");
		
		//test removal of city:
		System.out.println("World before Nowhereville removal and extra insert: \n" + w1 + "\n- - - - - - -\n");
		
		w1.removeCity("Nowhereville");
		w1.createAndInsertCity("San Fransisco");//this should NOT be inserted again because it's already in there.
		
		System.out.println("World after Nowhereville removal: \n" + w1 + "\n- - - - - - -\n");
		
		//extra equals test: everything above should basically make use everything in City
		// but just incase we test equals by itself
		// also tests multi-city World constructor
		City [] cities2 = {new City("Orlando"), new City("Tampa")};
		World w2 = new World("Mars", cities2);
		w2.insertCity(w1.getCity("Orlando"));
		System.out.println("City equality tests:\n ");
		System.out.println("True: " + w1.getCity("Orlando").equals(w2.getCity("Orlando")));
		System.out.println("True: " + w2.getCity("Tampa").equals(w1.getCity("Tampa")));
	}
}
