Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Topics This assignment will give you practice with line-based and token-based file processing, writing to a file, and String methods. Instructions You are

IN JAVA

Topics

This assignment will give you practice with line-based and token-based file processing, writing to a file, and String methods.

Instructions

You are going to write a program that will read the contents of an electronic diary. It will analyze each day as a good day :), a bad day :(, or a neutral day :|. The entry analysis will be grouped by month in a summary report that is written to a file.

Diary Entries

Each line in the diary will be a single entry.

It will begin with a 5 character date, where the first 3 characters indicate the month of the entry and the last 2 characters indicate the day of the entry.

After the date will follow all the text for that entry.

Jan01 New year: Everything is great! 

For the example above, "Jan01" is the date "New year: Everything is great!" is the diary text to analyze. You must use line-based file processing to access each entry in the diary, but you will need to use token-based processing to analyze the text for each entry.

diary.txt

The contents of the electronic diary will be stored in a file called diary.txt

Here is a sample diary.txt that you can use for testing your program:

Jan01 New year: Everything is great! Jan14 Today I got free ice cream. SO GOOD! #bestdayever Feb10 Meh. I'm fine. Feb21 I'm having a terrible horrible no good day. Feb23 Yesterday was horrible, but today is great! Yay! May02 Sad Panda. #terribleday May15 Hello World, today is fabulous! #yay Jun01 Great! Yay! Good! Yay! Happy. Happy. #goodgreatyay Jun11 Yay, yay, yay! I'm having an awfuly great day. 

Analyzing each entry

Each diary entry will be analyzed to determine if it is a good entry :), a bad entry :(, or a neutral entry :|. To determine this, you should code your program to look for six keywords (our program isn't very smart):

Good: "good", "great", "yay"

Bad: "terrible", "horrible", "awful"

Your program should count the number of occurrences of these keywords in a single entry.

If the count of good words is higher than the count of bad words, the entry is deemed good.

If the count of bad words is less than the count of good words, the entry is deemed bad.

If there are no good or bad words or the counts are the same, the entry is deemed neutral.

Jun11 Yay, yay, yay! I'm having an awfuly great day. 

In this June 11 entry, there are 4 good words ("Yay,", "yay,", "yay!", and "great") and 1 bad word ("awful").

Note that when analyzing each token, the word does not have to match exactly, it only must contain one of the keywords. The keywords should also be compared case insensitively.

4 good > 1 bad, so the entry is deemed good.

May02 Sad Panda. #terribleday 

In this May 11 entry, there are 0 good words and 1 bad word ("#terribleday").

1 bad > 0 good, so the entry is bad.

Writing the summary to a file

As you analyze each entry, you should print to the summary to a new file called summary.txt using a PrintStream. The format of the output should be such that each month is grouped together by month and each entry is recorded by it's date and one of the following three emoticons: :), :(, :| for good, bad, and neutral respectively.

So for the example above, summary.txt should contain:

Jan - 01 :) - 14 :) Feb - 10 :| - 21 :( - 23 :) May - 02 :( - 15 :) Jun - 01 :) - 11 :) 9 total days analyzed. 

Note that only the months that appear in the diary should appear in the summary.

In order to break apart the date for the summary, you will need to use methods from the String class (Links to an external site.)Links to an external site. to isolate the substring of the first few characters and the substring of the last few characters.

In order to print each month's heading, you will need to compare neighboring entries to determine when a new month has occurred.

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions