1. import java.util.Scanner;
  2.  
  3.  
  4. public class SpamFilterDriver
  5. {
  6.     private static SpamFilter filter;
  7.     private static final String FILENAME = "SpamFilter.obj";
  8.     private static final float SPAM_RATIO = (float) 0.05;
  9.    
  10.     static Scanner input = new Scanner(System.in);
  11.    
  12.     /**
  13.      * Main method. It calls the menu() method to obtain the user's selection
  14.      * and then makes a decison based upon the user's selection.
  15.      * @param args
  16.      *  Standard main method parameter, unused.
  17.      */
  18.     public static void main(String[] args)
  19.     {
  20.         boolean loop = true;
  21.        
  22.         while(loop)
  23.         {
  24.             char selection = menu();
  25.            
  26.             switch(selection)
  27.             {
  28.                 case 'C':
  29.                     checkEmail();
  30.                     break;
  31.                 case 'I':
  32.                     insertWord();
  33.                     break;
  34.                 case 'R':
  35.                     removeWord();
  36.                     break;
  37.                 case 'S':
  38.                     searchWord();
  39.                     break;
  40.                 case 'Q':
  41.                     loop = false;
  42.                     break;
  43.                 default:
  44.                     System.out.println("Invalid Selection!\n\n");
  45.                     break;
  46.             }
  47.         }
  48.     }
  49.    
  50.     /**
  51.      * Prints a menu and asks for a user's selection
  52.      * @return
  53.      * returns the user's selection.
  54.      */
  55.     private static char menu()
  56.     {
  57.         System.out.print("Welcome to the Spaminator\nPlease select an option:\n\n" +
  58.                 "C: Check Email\nI: Insert Word\nR: Remove Word\nS: Search For Word\n" +
  59.                 "Q: Quit\n\nSelection:");
  60.         String temp = input.nextLine().trim();
  61.         if (temp.length() == 1)
  62.         {
  63.             char answer = temp.charAt(0);
  64.             answer = Character.toUpperCase(answer);
  65.             return answer;
  66.         }
  67.         else return 'z'; // arbitrary invalid selection
  68.     }
  69.     /**
  70.      * Searches for a specified word in the hash table and prints a message
  71.      * that lets the user know if the word is or is not in the table.
  72.      */
  73.     private static void searchWord()
  74.   {
  75.       System.out.print("Word to find: ");
  76.       String checkMe = input.nextLine();
  77.        
  78.         boolean isFound = filter.isBadWord(checkMe);
  79.      
  80.       if(isFound)
  81.         System.out.println(checkMe + " is a bad word");
  82.       else
  83.         System.out.println(checkMe + "was not found in the list of bad words");
  84.   }
  85. /**
  86.  * Removes a word from the hash table. If the element to be removed is not
  87.  * found, it prints an error message instead.
  88.  */
  89.     private static void removeWord()
  90.   {
  91.         System.out.print("Word to remove: ");
  92.       String removeMe = input.nextLine();
  93.      
  94.       try
  95.     {
  96.         filter.remove(removeMe);
  97.         System.out.println(removeMe + " was successfully rmoved from the list" +
  98.                 " of bad words.");
  99.     }
  100.     catch (ElementNotFoundException e)
  101.     {
  102.         System.out.println(e.getMessage());
  103.     }
  104.      
  105.   }
  106.    
  107. /**
  108.  * Inserts a word into the hash table.
  109.  */
  110.     private static void insertWord()
  111.   {
  112.         System.out.print("Word to insert: ");
  113.       String insertMe = input.nextLine();
  114.      
  115.       filter.insert(insertMe);
  116.       System.out.println(insertMe + " added successfully!");
  117.   }
  118.  
  119.     private static void checkEmail()
  120.   {
  121.       // TODO Auto-generated method stub
  122.      
  123.   }
  124.  
  125.    
  126.    
  127.     private static void loadFilter()
  128.     {
  129.         //TODO
  130.     }
  131.    
  132.     private static void  saveFilter()
  133.     {
  134.         //TODO
  135.     }
  136. }