Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Full program in Java:

\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=FeCl3 KMnO+HCl=KCl+MnCl2+H2O+Cl2 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

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago