Lab 3

Due Monday, 2/23 - 1:00PM

  1. Implement a program that repeatedly (in a loop) prompts the user for an email address and sends a pre-configured message to each address entered by the user.  The user should be able to quit the program by entering a value (such as 0 or 'quit') to end the loop.  Hints:
    1. You need to add two properties to the Properties object you create (see the Project 2 description).  The Properties object is essentially a HashMap that stores key, value pairs representing relevant properties associated with the message.  The first property you need to set is the mail server.  The key for this property should be "mail.smtp.host" and the value should be "smtp.usfca.edu".  The second property you need to set is the sender.  The key for this property should be "mail.from" and the value should be your email address.
    2. You will need to import the following classes:
      1. import java.util.Date;
        import java.util.Scanner;
        import java.util.Properties;
        import javax.mail.Message;
        import javax.mail.MessagingException;
        import javax.mail.Session;
        import javax.mail.Transport;
        import javax.mail.internet.MimeMessage;

  2. Implement a program that reads the contents of a file such as the dracula.txt file attached at the bottom of the page and builds a HashMap of ArrayLists that stores a mapping from each word in the document to a list of the locations where the word occurs.  The requirements of the program are as follows:
    1. The user will enter the name of the file to be processed.
    2. Your program will process the file and generate the HashMap of ArrayList objects.  For example, if your document contained the following text "The cat and the dog ran." your HashMap would have 5 key, value pairs where the keys would be as follows: {the, cat, and, dog, ran}.  The value for 'the' would be an ArrayList containing the integers 1 and 4 since the word 'the' appears at positions 1 and 4 in the document.  The value for 'cat' would be an ArrayList containing the integer 2, and so on.
    3. Once the data structure has been built, allow the user to repeatedly (in a loop) enter search words.  For each word entered, print a list of the locations where the word occurs and then prompt for the next word.
    4. Hint: you can remove punctuation characters by calling the following method on a string and saving the result: replaceAll("\\W", "")  In this example, \\W is a regular expression specifying any non-word charcater.  Any non-word character is replaced with nothing.  You can also use the String toLowerCase method to convert the entire word to lower case.
Submission Instructions
ċ
dracula.txt
(849k)
Sami Rollins,
Jan 19, 2009, 6:00 PM
Comments