Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey guys i have a question on how to solve this java question using methods. just static methods file processing no private class/append/array a report

Hey guys i have a question on how to solve this java question using methods. just static methods file processing no private class/append/array

a report that is written to a file.

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.
  • I recommend writing the program without the file output to start. Once you get that part working, then print it to the file instead of the console.

Creating Formulas

Each line of the file will contain a number of elements each separated by a space. These elements are guaranteed to be grouped when there are several of the same element. You need to count the number of grouped elements by counting the number of occurrences of that element and then include that count after the element in the formula, except when there is only one.

For example:

H H O O

should become H2O2 because there are two H's followed by two O's.

and

K H C C C C H H H H O O O O O O

should become KHC4H4O6 combining the C's H's and O's

Naming the Compound

After you construct the formula for a given line in the log, you should then determine if the common name of that compound is known or unknown. Your program only knows the following six compounds:

  • NaHCO3 is Baking Soda
  • H2O2 is Liquid Bleach
  • KHC4H4O6 is Cream of Tartar
  • N2O is Laughing Gas
  • NaCl is Salt
  • C12H22O11 is Sugar
  • All other compound formulas are unknown

Your program should compare the formula you created to these known compounds, printing the compound name if known and "UNKNOWN FORMULA" followed by the formula if the compound is unknown.

Writing the summary to a file

As you analyze each line, you should print a summary to a new file called report.txt using a PrintStream. The summary should include the name of the compound (if known) or UNKNOWN FORMULA followed by the formula created for that entry (if unknown).

The file should also include a total count of formulas processed, as well as the count of the total and the percentage of unknown formulas.

Note that the percentage is printed to the screen without any decimal places.

sample

Example 1

So for the contents of log.txtimage text in transcribed,

N N O Na Cl N N O Na Cl K H C C C C H H H H O O O O O O C C C C C C C C C C C C H H H H H H H H H H H H H H H H H H H H H H O O O O O O O O O O O N N O O O O O N N O Na H C O O O H H O O 

report.txtimage text in transcribed should contain:

Let's do some chemistry... Laughing Gas Salt Laughing Gas Salt Cream of Tartar Sugar UNKNOWN FORMULA (N2O5) Laughing Gas Baking Soda Liquid Bleach 10 total formulas processed. 1 (10%) unknown formulas.
Transcribed image text

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions