Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write full program in java using scanner to read file using user input: The first number in the file will be used to tell the

Write full program in java using scanner to read file using user input:

The first number in the file will be used to tell the program how many equations to balance.

image text in transcribed

image text in transcribed

4(). Write a program to balance chemical equations. An equation is comprised of a list of compounds and elements, separated by plus-signs, on both sides of an equal sign. An element will be represented by either one or two letters; the first is always capitalized, and if the element has a second character, it will be lowercase. Compounds are composed of several elements added together that may have parenthesis around them and with a number following each element. This number represents the number of atoms of the element in front of the number in the compound. If there is only one atom of an element in the compound, no number will appear after the element. The result is the lowest number of integer coefficients for each compound needed so the equation is balanced. An equation is balanced when the number of atoms of each element on the left side is equal to that of the right side. Coefficients are applied to the complete compound; so, a coefficient of two for FeCl represents two atoms of Fe and two atoms of Cl. Input is from a text file, where the first line contains an integer N between [1, 30]. The following N lines define equations according to the rules described above. For each labeled equation, output to the screen the balanced equation with the lowest integer number coefficients. If an equation cannot be balanced correctly or uniquely, output the words "Cannot Balance". Let the user enter the file name from the keyboard. Refer to the sample output below. Sample File: 5 Fe+Cl2=FeCl13 KMnO+HCl=KCl+MnCl2+H2O+Cl2 C8H18+O2=CO2+H2O Fe2(SO4)3KSCN=K3Fe(SCN)6K2SO CO2=CO Sample Run: Enter the file name: balequation.txt E1:2Fe+3C12=2FeCl E2:2KMnO4+16HCl=2KCl+2MnCl2+8H2O+5Cl2 E3:2C8H18+2502=16CO2+18H20 E4:Fe2(SO4)3+12KSCN=2K3Fe(SCN)6+3K2SO4 E5: Cannot Balance

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_2

Step: 3

blur-text-image_3

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago