title: Four color theorem Java implementation of U.S. map
body: <p>I am attempting to assign a color to each of the states so that no two adjacent states share the same color (<a href="http://en.wikipedia.org/wiki/Four_color_theorem">http://en.wikipedia.org/wiki/Four_color_theorem</a>). The program will output each state and its color.</p>
  
  <p>I'm reading in a text file with the following format for 48 states (2 aren't connected):</p>
  
  <pre><code>al,fl,ms,tn,ga
  ar,la,tx,ok,mo,tn,ms
  az,ca,nv,ut,nm
  ca,az,nv,or
  co,wy,ut,nm,ok,ks,ne
  ...
  </code></pre>
  
  <p><b>Example:</b></p>
  
  <p>Alabama touches Florida, Mississippi, Tennessee, and Georgia.</p>
  
  <p>Arkansas touches Louisiana, Texas, etc.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>MapColor.java    
  
  import java.io.*;
  import java.util.*;
  
  public class MapColor {
  
      public static void main(String[] args) throws IOException {
  
          ArrayList &lt;String&gt; statestemp = new ArrayList &lt;String&gt; ();
          ArrayList &lt;State&gt; states = new ArrayList &lt;State&gt; ();
  
          // read in each line
          BufferedReader reader = new BufferedReader(new FileReader("usa.txt"));
          String line = null;
          while ((line = reader.readLine()) != null) {
              statestemp.add(line);
          }
          reader.close();
  
          // create all state objects and adjacencies
          for (int i = 0; i &lt; statestemp.size(); i++) {
              State st = new State();
              String[] str = statestemp.get(i).split(",");
              st.setName(str[0]);
              for (int j = 1; j &lt; str.length; j++) {
                  st.addAdj(str[j]);
              }
              states.add(st);
          }
  
          // set colors
  
  
          // print out states and adjacencies
          for (State s : states) {
              System.out.println("Name: " + s.getName());
              System.out.println("Color: " + s.getColor());
              System.out.print("Adj: ");
              s.getAdj();
              System.out.println();
              System.out.println();
          }
  
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>State.java
  
  import java.util.ArrayList;
  
  public class State {
  
      public String n = null;
      public int c = 0;
      public ArrayList &lt;String&gt; adj = new ArrayList &lt;String&gt; ();
  
      public String getName() {
          return n;
      }
      public void setName(String name) {
          this.n = name;
      }
      public int getColor() {
          return c;
      }
      public void setColor(int color) {
          this.c = color;
      }
      public void addAdj(String s) {
          this.adj.add(s);
      }
      public ArrayList &lt;String&gt; getAdj() {
          return this.adj;
      }
  }
  </code></pre>
  
  <p>I am at the point where I would like to begin assigning colors, but I am unsure how to go about making comparisons.</p>
  
  <p>Any suggestions would be appreciated!</p>