Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SpamFilterDriver
- {
- private static SpamFilter filter;
- private static final String FILENAME = "SpamFilter.obj";
- private static final float SPAM_RATIO = (float) 0.05;
- static Scanner input = new Scanner(System.in);
- /**
- * Main method. It calls the menu() method to obtain the user's selection
- * and then makes a decison based upon the user's selection.
- * @param args
- * Standard main method parameter, unused.
- */
- public static void main(String[] args)
- {
- boolean loop = true;
- while(loop)
- {
- char selection = menu();
- switch(selection)
- {
- case 'C':
- checkEmail();
- break;
- case 'I':
- insertWord();
- break;
- case 'R':
- removeWord();
- break;
- case 'S':
- searchWord();
- break;
- case 'Q':
- loop = false;
- break;
- default:
- System.out.println("Invalid Selection!\n\n");
- break;
- }
- }
- }
- /**
- * Prints a menu and asks for a user's selection
- * @return
- * returns the user's selection.
- */
- private static char menu()
- {
- System.out.print("Welcome to the Spaminator\nPlease select an option:\n\n" +
- "C: Check Email\nI: Insert Word\nR: Remove Word\nS: Search For Word\n" +
- "Q: Quit\n\nSelection:");
- String temp = input.nextLine().trim();
- if (temp.length() == 1)
- {
- char answer = temp.charAt(0);
- answer = Character.toUpperCase(answer);
- return answer;
- }
- else return 'z'; // arbitrary invalid selection
- }
- /**
- * Searches for a specified word in the hash table and prints a message
- * that lets the user know if the word is or is not in the table.
- */
- private static void searchWord()
- {
- System.out.print("Word to find: ");
- String checkMe = input.nextLine();
- boolean isFound = filter.isBadWord(checkMe);
- if(isFound)
- System.out.println(checkMe + " is a bad word");
- else
- System.out.println(checkMe + "was not found in the list of bad words");
- }
- /**
- * Removes a word from the hash table. If the element to be removed is not
- * found, it prints an error message instead.
- */
- private static void removeWord()
- {
- System.out.print("Word to remove: ");
- String removeMe = input.nextLine();
- try
- {
- filter.remove(removeMe);
- System.out.println(removeMe + " was successfully rmoved from the list" +
- " of bad words.");
- }
- catch (ElementNotFoundException e)
- {
- System.out.println(e.getMessage());
- }
- }
- /**
- * Inserts a word into the hash table.
- */
- private static void insertWord()
- {
- System.out.print("Word to insert: ");
- String insertMe = input.nextLine();
- filter.insert(insertMe);
- System.out.println(insertMe + " added successfully!");
- }
- private static void checkEmail()
- {
- // TODO Auto-generated method stub
- }
- private static void loadFilter()
- {
- //TODO
- }
- private static void saveFilter()
- {
- //TODO
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement