Sei sulla pagina 1di 7

Computer Science 2631 – Assignment 1 - Fall 2018

Assignment 1: Mail Message System


Given: Thursday, September 6, 2018
Electronic Copy Due: Friday, September 28, 2018

Objectives:

• to practice using Java.

• to gain experience writing Java classes.

• to gain experience with Java arrays.

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

Welcome to the Secure Corp. messaging system.

Reading mail from "mail.txt"... done.

Enter your name (be honest): Jason

Hello, Jason, you have 2 unread messages.

Available Options
  L - List your messages
  V - View a message
  C - Compose a message
  S - Switch users
  Q - Quit

Please enter your choice:

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

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:

<Message Number> <Status Character>


<Message Sender>
<Message Recipient>
<Message Subject>
<Message Body Line 1>
<Message Body Line 2>
...
<Message Body Line n (Last Line)>
EOF

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

Choice L: List Your Messages

The program must list all messages to the current user.

Please enter your choice: L

# 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

Please enter your choice:

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.

Please enter your choice: V

Which message would you like to view: 12

Message #12 (New)


From: Bob
Subject: Dinner Thursday
----------
Hi Jason,

I don’t think we can make it to dinner on Thursday---Julia’s knees aren’t what


they used to be. Maybe next week?

Bob
----------

Available Options
  L - List your messages
  V - View a message
  C - Compose a message
  S - Switch users
  Q - Quit

Please enter your choice:

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

Which message would you like to view: 20

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

Please enter your choice:

Choice C: Compose a Message

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:

Please enter your choice: C

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

Message #20 sent to Bob.

Available Options
  L - List your messages
  V - View a message
  C - Compose a message
  S - Switch users
  Q - Quit

Please enter your choice:

5
Choice S: Switch Users

The program should ask for the users name and switch to displaying everything for that user.

Please enter your choice: S

Enter your name (be honest): Jemma

Hello, Jemma, you have 8 unread messages.

Available Options
  L - List your messages
  V - View a message
  C - Compose a message
  S - Switch users
  Q - Quit

Please enter your choice:

Choice Q: Quit

The program should write all of the messages to the file mail.txt and then quit.

Please enter your choice: Q

Thanks for using the Secure Corp. messaging system.

Writing mail to "mail.txt"... done.

Design and Implementation


The program must use at least two Java classes that you create on your own. One class must hold a
single mail message while another class holds the mail system and has methods to perform all of the
above tasks (except the user input). Some important requirements:

• 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.

• All fields in your classes must be private.

• 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

• Message Status (New or Read)

• 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.

Submission and Marking


Create a folder named Lastname_Firstname_Asg01 and place your .java files in the folder. Submit your
source code to the submit folder (I:\Labs\CompSci\Submit\2631\001). If you are submitting your files via
the web interface from off campus, you will need to compress your files into one .zip file. There will
be marks for naming your submission correctly.

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.

Potrebbero piacerti anche