Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Write in Java:

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

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

Students also viewed these Databases questions

Question

Describe the origin of coffee.

Answered: 1 week ago

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago