We are not advocating that each of you join the ranks of the spam senders of the world, but some knowledge of how those people work probably is useful. In this program, you will take arbitrary test string from the user, and you will output each valid email address within that string.
A valid email address is defined as one or more alphanumeric characters (with potential intervening in-between periods but no whitespace), followed by the "at" sign, followed by one or more alphanumeric characters (with potential intervening intermediate periods but no whitespace).
Your program should prompt the user for a text string, then output the valid email address (one per line). It should then prompt the user whether s/he wants to enter another line, taking 'y' or 'n' as answers. So, example output would be
Enter a text string here is a line with some stuff and smith@ibm.com going to the store Valid email addresses are: smith@ibm.com Do you want to enter another line (y/n)? y Enter a text string We are driving down the road. Valid email addresses are: None Do you want to enter another line (y/n)? y Enter a text string This line has two emails: bill.wilson@cs.brown.edu and jw23@mail.gatech.edu Valid email addresses are: bill.wilson@cs.brown.edu jw23@mail.gatech.edu Do you want to enter another line (y/n)? n
Advice: Get your program working on general examples above then start thinking about more difficult cases. For example, below are some more challenging examples:
This string has one valid email john@apple.com! Valid email addresses are john@apple.com --------------------------------------------------------------- smith@@earthlink.com @xyz.com ab%cd@xyz.com&& --bg@mailer..com. Valid email addresses are cd@xyz.com bg@mailer..com --------------------------------------------------------------- <P><H1>smartgirl@www.turner.com</H1></TABLE></P> Valid email addresses are smartgirl@www.turner.com
Some of these are very difficult to handle correctly. Try to get your program working on the straightforward examples first, then work on the more challenging ones if you have time.
Make sure to use good modular programming style. Write a class Spammy.java that simply handles the input/output interaction with the user. Also write EmailFinder.java that provides an object that does the email address extraction, similar to what was done with the Pig Latin program. Break your classes into sufficient methods so that your program is a good modular design that helps you analyze and debug it.
TURN IN: EmailFinder.java, Spammy.java
We will design a simple robot program that could form the basis for a more complex program later. Your job is to write an applet which displays and controls two robot teams.
For this you will first need to develop a Robot class. A Robot has a name and each robot instance should have a unique id number that is generated by the class. Robots know their current location on the screen (x,y). The robot constructor should take a name, a team and a start location as parameters. The constructor should then be able to assign the robot its unique id number.
If a robot is given a graphics context (Graphics object) and it can draw itself at its current location. A robot should draw its shape and then print its name inside the shape.
Robots also move. The command to move is given by cardinal direction. To move up the screen, the command is robot1.move('n'); Likewise, 's' moves down the screen, 'e' moves right, and 'w' moves left. If a robot reaches the edge of the screen, then it should ignore any commands to continue in that direction. Thus if a robot is all the way at the top of the screen and it receives a move('n') message, it should do nothing. The movement distance on each turn is the robot's width (thus if the robot is a 50 pixel circle, it will move 50 pixels for each move messge received).
A Robot team is a collection of 3 robots. Each robot team has a team color. The team can draw itself on the current Graphics context. A team constructor takes the references to 3 robots as its team members, its movement method, and a color as its team color. The movement method should be coded as publicly available constants (RANDOM=1, LOCK_STEP=2); If no movement method is provided, the team should move randomly.
Teams can move in one of two ways, random or lock-step. If the team movement is random, each time a move message is received, each robot moves independently n, e, s or w. If the team movement is lock-step, all the robots on the team will move in the same random direction (n,e,s,w).
The RobotApplet should create two teams of three robots each. Each team should have a different color. One robot team should move in lock-step, one should move random. Every time the applet is started, the teams should move. The robots should be created so that they are initially lined up vertically, one team on the left edge of the screen and one team on the right edge.
For this problem, you probably want to review the start/stop/init methods in section 4.6 of the text and the Diner problem we did in recitation last week.
For more advanced students (If you want to explore some more advanced things).:
You probably notice that sometimes a robot will overlap another because a team member hits a boundary and can't move, but the second robot can and then gets hidden. Add some logic to detect and prevent this condition.
TURN-IN
Robot.java
RobotApplet.java
RobotTeam.java