Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in JAVA: Write a program to balance chemical equations. An equation is comprised of a list of compounds and elements, separated by plus-signs, on

Write in JAVA: 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 = FeCl3

KMnO4 + HCl = KCl + MnCl2 + H2O + Cl2

C8H18 + O2 = CO2 + H2O

Fe2(SO4)3 KSCN = K3Fe(SCN)6 K2SO4

CO2 = CO

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

=+ Where would most corporations like the balance to fall?

Answered: 1 week ago

Question

List out some inventory management techniques.

Answered: 1 week ago

Question

Calculate the lifetime value (LTV) of a loyal customer.

Answered: 1 week ago

Question

Use service tiering to manage the customer base and build loyalty.

Answered: 1 week ago