Solved Homework: Question: No use of arrays is permitted, only line-based and token-based processing is allowed, no private …

No use of arrays is permitted, only line-based and token-based processing is allowed, no private static.

You are going to write a program that will read the contents of a series of emails and determine which emails should be considered spam. The analysis will be printed in a summary report that is written to a file.

Email Messages

Each email message will contain:




Message body

—eom— (this exact String will be on a line of its own and designate the end of message)

For example:

From: Russell Wilson
To: Tyler Locket
Subject: SP for PC


The surprise party for Pete is coming up. Do we need to get
anything else? We're down to the wire.

Let me know if I need to collect more funds from the team.


Your program will use line-based file processing to access each line in the email message, but will need to use token-based processing to analyze the message body for each email.


The contents of all emails (one after the other) will be stored in a file called emails.txt

Analyzing each email

Each email will be analyzed to determine how likely it is to be spam. Our program is not very smart, so it simply counts the number of times that a spam-like word appears in the email. Words to look for include:

offer, wire, bank, fund, transfer, lottery

Your program should count the number of occurrences of these keywords in a single email. Note that keyword searching should be case-insensitive and the words may be partial words of a larger word (“fund” in “Fundraising” counts as an occurrence).

Consider the email above from Russell Wilson to Tyler Locket, there are 2 keywords present “wire” and “fund” (in “funds”).

Threshold for spam keywords

You should create a class constant at the top of your program. If the number of spam keywords for an email is greater than or equal to the threshold, then that message should be considered spam.

In the case of the email from Russell Wilson above, if the threshold is 2, the message would be considered spam. If the threshold is 3, the message would not be considered spam (since there are only 2 keywords in the email).

Writing the summary to a file

As you analyze each email, you should print to the summary to a new file called summary.txt using a PrintStream. The summary should include the subject of each email; however, if an email is deemed spam, the marker **SPAM** should appear in front of the subject.

So for the contents of this emails.txt, summary.txt should contain:

Ignore the robots reading your emails...

         I ran out of cookies
         From the bottom of my heart...
**SPAM** Immediate Attention Requested
**SPAM** You're a winner!
**SPAM** Your trees are so happy!
         (no subject)
         Don't forget!
**SPAM** SP for PC

8 emails processed.

In order to print the subject of each email, you will need to “remember” this information from the beginning of the message until after the entire message is processed (the —eom— is reached).

Finally, you should print a count of the number of email analyzed.

Program Development

You must break your program into a minimum of 3 methods, including the main. Each method should accomplish a specific task and be appropriately named.

Expert Answer

written is a java program to read emails and generate spams into text file called summary.txt
 Make change to the threshold limit of spam words it going to contain.(I Gave 3)
 Give the location of the file email.txt into the file path on line 18.
import java.util.Scanner;

public class EmailSpamChecker {
    final static int threshold = 3;

    public static void main(String[] args) throws Exception {
        File file = new File("C:\java\emails.txt"); //Specify your file path

        Scanner inputEmail = new Scanner(file);
        String line = null;
        String subject = "";
        String lineForCheck;
        File writeFile = new File("summary.txt");
        FileWriter fr = null;
        int count = 0;
        fr = new FileWriter(writeFile);
        while (inputEmail.hasNextLine()) {
            count = 0;
            while (true) {
                line = inputEmail.nextLine();
                lineForCheck = line.toLowerCase();
                if (!line.equals("---eom---")) {

                    if (lineForCheck.contains("offer")) {
                    if (lineForCheck.contains("wire")) {
                    if (lineForCheck.contains("bank")) {
                    if (lineForCheck.contains("fund")) {
                    if (lineForCheck.contains("transfer")) {
                    if (lineForCheck.contains("lottery")) {
                    if (lineForCheck.contains("subject: ")) {
                        subject = line.substring(9);
                } else
            try {
                if (count > threshold) {
                    fr.write("***SPAM***" + subject + "n");
                } else
                    fr.write(subject + "n");
            } catch (IOException e) {


        // close resources
        try {
        } catch (IOException e) {
Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.


Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.


Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.


Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?