Dates Program

Wikipedia contains an article for each year – e.g. 1953 – with a variety of significant events, birthdays, etc.  If you go to Wikipedia and type any year, you’ll see the article.

You can COPY all the events and save them in a TEXT file – use a text editor like Notepad or Scite.  You will need to clean up a few little details.  Then your text file should look something like this:

June 16 - Soviet Union and Yugoslavia form diplomatic relations.
June 17 - Workers Uprising: In East Germany, the Soviet Union orders a division of troops…
June 18 - Egypt declares a republic.
June 19 - Execution of Julius and Ethel Rosenberg.
June 21 - Birth of Benazir Bhutto
June 30 - The first Chevrolet Corvette is built at Flint (Michigan).
July 4 - Strikes and riots in coal mining regions in Poland
July 5 - First meeting of the assembly of the European Economic Community in Strasbourg, France.
July 10 - Soviet official paper Pravda announces that Lavrenti Beria has been deposed from …
July 26 - Fidel Castro and his brother lead a disastrous assault on the Moncada Barracks…

Now you can write a Java program to open the file, read each line, and SEARCH for something.  For example, you might want to search for “Germany” to see if there were any significant events in Germany in 1953.  Here is a program that does this:

 

The program inputs a word (Germany) to search for and the name of a file (1953.txt).  Then it prints out the matching events, like this:

img1.gif

This basic concept leads to a small project, described below.

  1. Get a copy of the program and 10 sequential years of text files from Wikipedia.
    Go to Wikipedia and copy the data into a text editor.  Remove any extra stuff,
    leaving one event per line.
  2. Add a button to search for two words, using OR logic.  For example:
    "Germany"  or  "France"
  3. Add a button to search for two words, using AND logic.  For example:
    "Germany" and "economy"
  4. Add a LIST box containing the names of the 12 months.  
    Add a button that asks for the year and then prints all the events (or births) in that month.
  5. Make a method that searches in ALL the text files for a specific word,
    and displays ALL the results in the TextArea.  The method should use a LOOP to
    go through all the files - all the file names should be stored in an array.
  6. Add a HELP button that describes the function of each button (feature).
  7. Add any other features you think might be useful or interesting.
    Be sure to include a short description in the help file.
    To score a top grade (7) you must invent at least 2 more features.
  8. Turn in the WORKING program, with all your text-files, on Monday 9 March. 

== List Box ==

For #5, you are supposed to make a List box containing the names of the months.
Here is a sample program demonstrating how to do this.

import java.awt.*;

public class ListSample extends EasyApp
{
   public static void main(String[] args)
   {
      new ListSample();  
   }

   List months = addList("Jan|Feb|Mar|Apr",50,50,100,300,this);

   Button num = addButton("Num",10,100,40,30,this);

   public void actions(Object source, String command)
   {
      if (source == num)
      {
         int monthNum = months.getSelectedIndex();
         output("You clicked on month # " + monthNum);
      }
      else if (source == months)
      {
         String monthName = months.getSelectedItem();
         output("You clicked on " + monthName);
      }
   }                                                 
}