title: Binary Search text file that was put into an Array<Integer> using Java
body: <p>I'm kind of new to the whole programming thing and still get stuck. I have been working on a class assignment for the past 3 days and this is due tonight, so would REALLY appreciate any help offered.</p>
  
  <p>Instructions:
  You are provided a file that contains (semi-random) years from modern history with the earliest year first. Write a program that:</p>
  
  <ol>
  <li><p>Reads in the file</p></li>
  <li><p>Re-sorts it with the latest events first</p></li>
  <li><p>Determines whether the founding of CMU in 1892 was considered a world historic event</p></li>
  <li><p>If not so yet, add the event to a new list of events</p></li>
  <li><p>Writes the new list of events to a file.</p></li>
  </ol>
  
  <p>Hints: </p>
  
  <p>Choosing the right search approach allows you to make insertion a lot easier.</p>
  
  <p>Here is the information listed in the events.txt file:</p>
  
  <p>1066
  1095
  1100
  1206
  1215
  1260
  1271
  1273
  1300
  1347
  1399
  1438
  1455
  1492
  1509
  1513
  1517
  1519
  1520
  1522
  1543
  1582
  1603
  1605
  1609
  1637
  1643
  1664
  1667
  1684
  1690
  1721
  1755
  1760
  1762
  1764
  1769
  1776
  1787
  1789
  1792
  1796
  1808
  1815
  1819
  1826
  1833
  1842
  1859
  1862
  1867
  1876
  1879
  1880
  1885
  1893
  1895
  1897
  1900
  1903
  1905
  1907
  1911
  1913
  1914
  1916
  1917
  1918
  1922
  1927
  1928
  1929
  1936
  1939
  1942
  1945
  1946
  1947
  1949
  1950
  1953
  1954
  1957
  1959
  1969
  1980
  1981
  1989
  1991</p>
  
  <p>Here is one of the codes that I've got so far:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  import java.util.Scanner;
  
  public class Assignment7 {
  
  public static void main(String[] args) throws IOException {
  
  
  
      System.out.println("Accessing Central Michigan University Historical Records...");
      System.out.println("Listing all CMU Historical Event Dates: ");
  
  
  
  
  
      Scanner file = null;
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
  
      try {
      file = new Scanner(new File("events.txt"));
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      }
      while(file.hasNext()){
      if (file.hasNextInt()) list.add(file.nextInt());
      else file.next();
  
          }
  
  
  
      {
  
  
      Collections.reverse(list);
      for (Object i: list) 
          System.out.println(i);
  
  
  
  }
  }
  }
  </code></pre>
  
  <p>Any help that is offered will be GREATLY appreciated. </p>
  
  <p>Here is the output I get without the last piece of code that I need to perform the binary search.</p>
  
  <pre><code>Accessing Central Michigan University Historical Records...
  Listing all CMU Historical Event Dates: 
  1991
  1989
  1981
  1980
  1969
  1959
  1957
  1954
  1953
  1950
  1922
  </code></pre>
  
  <p>...and so on to 1066 </p>
  
  <p>Entered the piece of code below to attempt the binary search but got the message "The method add(int, int) is undefined for the type Scanner" Not sure how to fix this. Like I said NEWB and I mean VERY NEW, first semester of programming w/ java.</p>
  
  <pre><code>int key = 1892;
  int pos = Collections.binarySearch(list, key);
  if (pos &lt; 0)
  file.add(-pos-1, key);
  </code></pre>