Professional Documents
Culture Documents
Assignment 1 - Mail System
Assignment 1 - Mail System
Objectives:
The Problem
Secure Corp. wants to introduce an electronic messaging system for use in its most secure
departments. The head honchos think that any code written outside of the company might have
security flaws (intentional or accidental), and therefore want to create a system in house. You have
been selected to write that system. Since they want you to take the utmost care and give the system the
attention to detail that it requires, you have been given three weeks to complete the system.
The Program
The program will use a text file to store the mail messages. Secure Corp. believes that any network
activity is inherently insecure, and therefore will dedicate one machine as the mail machine, which
will be used by multiple users.
Upon launching the program, the program should open mail.txt and read all of the messages into the
system. Then the user should be prompted for their name, told how many unread messages they have,
and should finally be presented with a menu (user input is in bold for all examples):
The program will use a text file to store the mail messages. Secure Corp. believes that any network
activity is inherently insecure, and therefore will dedicate one machine as the mail machine, which
will be used by multiple users.
Upon launching the program, the program should open mail.txt and read all of the messages into the
system. Then the user should be prompted for their name, told how many unread messages they have,
and should finally be presented with a menu (user input is in bold for all examples):
1
$ java MailProgram
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
Feel free to rename your program as you wish. Both upper and lower case characters should be
acceptable. The program should continue until the user selects quit. Any invalid input should print an
error message and present the menu again.
The mail data file is a text file with mail messages in it. You may assume that the mail file is correct
(error checking is not required). If the file does not exist, the system should simply start with no
messages. The format of the file is a sequence of messages. Each message is broken down as follows:
Where the status character is either 'N' for new or 'R' for read. One example message is:
2
7 R
Bob
Jemma
I can’t believe I ate the whole thing.
Hi Jemma,
Your cake was delicious. I actually ate the whole thing last night. What was
your secret ingredient? You promised you’d tell me after I ate it.
Bob
EOF
# S From Subject
----------------------------------------------------
17 N Jon Jacob Jingl Oh, Really...
12 N Bob Dinner Thursday
8 Jemma Expense Report
6 Harry True Story!
2 Jemma I really really want to talk t
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
The first column gives the message number (used when viewing the message), with space for three
digit numbers. The second column is a single character, which is either 'N' if the message is new, or
blank (' ') if the message has been read. The third column indicates who the message is from. This
column has exactly 15 characters. The final column is 30 characters wide and is the subject of the
message. There is always exactly one space between each of the columns, and that the fields are
shortened to ensure that they fit into the column widths. In message #17 the sender (Jon Jacob
Jingleheimer Schmidt) has been shortened to fit in the column, and in message #2 the subject has been
shortened.
3
Choice V: View a Message
The program should ask the user which message they would like to view. If that message is to the
current user, it should be displayed.
Bob
----------
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
The format of the message should be similar to what is shown above. Once the message has been
viewed, it should be set as read and should not appear as new in the list or message view any more. If
the message does not exist or is not addressed to the current user, the following should occur:
4
Please enter your choice: V
I’m sorry; message #20 is not addressed to you or does not exist.
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
The program should ask the user for the recipient (only one), subject and body of the message. The end
of the body will be indicated by the phrase "EOF". For example:
Recipient: Bob
Subject: Dinner Next Week
Body (enter EOF to end body):
Hi Bob,
Of course I knew that about Julia, I’m sorry that I didn’t think about that
ahead of time. How about next Wednesday you come over for Mexican, and we’ll
skip the football?
Jason
EOF
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
5
Choice S: Switch Users
The program should ask for the users name and switch to displaying everything for that user.
Available Options
L - List your messages
V - View a message
C - Compose a message
S - Switch users
Q - Quit
Choice Q: Quit
The program should write all of the messages to the file mail.txt and then quit.
• You may not use any of the Java Collection classes for this assignment (ArrayList, Vector, HashMap,
etc.). If this requirement is not clear, please ask.
• There cannot be any use of System.in or System.out in your MailSystem or Message classes. You may
have methods that accept these values as parameters, but you may not access them directly in the
methods of these classes. To pass in System.in, your function must accept an InputStream parameter
6
(or you can pass in a Scanner object which refers to System.in). Similarly, System.out may be passed
in to a member function (its type is PrintStream).
Message Class
The Message class must hold all of the information for one message. This includes:
• Message Number
• Sender
• Recipient
• Subject
• Body
In addition, you will need methods to retrieve some or all of these values and a constructor and/or
methods to set all of this information. Also, it would simplify your program if you created some
methods to print a message to the screen, read a message from a file, and write a message to a file.
MailSystem Class
The MailSystem class must hold all of the messages for the system. At its most basic level, it has two
fields, which are an array of messages and a message count. You may assume that there will not be
more than 500 messages. It would also be helpful to have methods to retrieve a single message by its
number, print the messages for a given user, add a message to the system, write the messages to
mail.txt, and read the messages from mail.txt.
Your program must pass the course CheckStyle requirements for full marks on the style portion of the
assignment. If you have any questions on this requirement, please ask.
Automated testing will be used to validate your program. As a result, be sure your program does not
require any input other than that described in this handout. The output of the message table in
particular should match this handout exactly.