CS 201 - Computer Science I - Fall 2008
Lab 3 - Strings


Loyola College > Department of Computer Science > Dr. James Glenn > CS 201 > Labs > Lab 3

Due

Electronic version: Wednesday, September 24th at 11:59pm.
Labs submitted one day late will be assessed a 20% penalty. Labs will not be accepted more than one day late.

Objectives

Reading

Anderson and Franceschi, § 3.1-3.7

Introduction

There are five reasons for invoking methods:

In section 3.7, Anderson and Franceschi introduce the String class and some of the methods that can be used with it. Many more String methods are available; their descriptions can be found in the online Java API documentation.

For each method, the documentation lists the information you need to know in order to use the method. This information includes the following.

The documentation also lists a plethora of other classes. For each class, the documentation includes the name of the package it is in (this can be used with an import statement at the beginning of a file to allow you to use classes in that package), a description of the class, a list of the constructors that are available for that class, and a list of the methods that are available for that class.

Problem Description

In this lab you will learn about one of the techniques mass-marketing companies use to discover your e-mail address, called e-mail harvesting. An e-mail harvester is a program that seaches the Web for files containing e-mail addresses. For this assignment you will design a program that searches a user-provided string to see if it contains an e-mail address.

Assignment

Write a program called EmailHarvester that prompts a user for the for the text of interest. The program then displays the first e-mail address contained in that text. For our purposes an e-mail address is composed of an "@" and the two maximal-length strings that preceed and follow the "@" with no embedded whitespace. The program should output an "@" if no e-mail address is found. Your program should do the following:

Hint: Before you begin programming, you may want to sketch out a possible input and label the parts of the drawing that you are interested in so that you can visualize the specific information that will be stored during the intermediate steps of this program.

Once the program described above works, make your program more robust by verifying that the program works correctly by testing the following cases:

Hint: It is acceptable to modify the user's input as long as the modification does not effect the ability of the program to function correctly.

Exercise

Provide a memory use diagram that reflects the values in your variables and objects at the end of your code's execution. Include objects that no longer have references to them. Be sure to properly sketch primitive variables and reference variables (i.e. objects).

Submission

Submit the source code (.java file) as an attachment to an e-mail sent to your instructor. The exercise can be turned in as hardcopy or as another electronic attachment created with an application such as Microsoft Visio.
The original problem description is from Java Program Design by Cohoon, J. and J. Davidson, McGraw Hill Companis, Inc.: New York, 2004.

Dr. Dawn Lawrie wrote much of the instructions for this lab.