Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C# read the questions carefully and provide a code and explain IDEALGAS.CS Add a class to your project and call it IdealGas.cs .

This is C# read the questions carefully and provide a code and explain IDEALGAS.CS
Add a class to your project and call it IdealGas.cs.
The ideal gas class will have private fields for mass, volume, temp, molecular weight, and pressure.
Write public Get and Set methods for mass, volume, temp and molecular weight. Write only a Get method for pressure.
Write a private void and parameterless Calc method in the class that will use the private fields for mass, volume, temp and molecular weight to calculate pressure. Call this Calc() method from each of the set methods for mass, volume, temp and molecular weight.
IMPORTANT: The Set methods must have the word Set in the name, return void and have one parameter. The Get methods must have the word Get in the name, return the same type as the field they return and have no parameters. The calculate method must be private void and parameterless. The calculate method must be called from Set methods and NOT be called from Get methods.
PROGRAM.CS
Change program.cs so that it now instantiates the class and lets the class do the calculation of the pressure.
You will still likeley need the following methods in Program.cs: DisplayHeader, GetMolecularWeights, DisplayGasNames, GetMolecularWeightFromName, DisplayPresure, PaToPSI.
MAIN METHOD
The main method will do the following (Changes to the existing main method are underlined):
Declare double arrays for gas names and molecular weights. Declare an int to keep track of number of elements in the arrays.
Call DisplayHeader to show the program header.
Call GetMolecularWeights to fill the arrays and get the count of items in the list.
Call DisplayGasNames to display the gas names to the user in three columns.
In a do another loop do the following:
Ask the user the name of the gas.
Use GetMolecularWeightFromName method to get the molecular weight of the gas selected by the user.
If the gas is not found display an error message, and drop out to the do another loop.
If it is found, Instantiate an IdealGas object (something like IdealGas gas = new IdealGas();)
Ask the user for the volume of gas in cubic meters, mass of the gas in grams and temperature in celcius.
Use the IdealGas SetMolecularWeight, SetVolume, SetMass and SetTemperature methods to set the values receive from the user into the gas. The class will automatically calculate pressure.
Use the IdealGas GetPressure method to pass the pressure in pascals to the DisplayPressure method to display the pressure in Pascals and Degrees Celcius.
Ask the user if they want to do another.
Display a good bye message when they are done.
EXCEPTION HANDLING
You will also modify program.cs so that it uses exception handling.
Inside the do another loop add a try catch block. Catch the following exceptions: FormatException, OverflowException and generic Exception. In each catch block display an appropriate message. In the final Exception block display the exceptions message (something like: Console.WriteLine("Error: "+ exc.Message);)
Make sure an exception does not stop the program and allows the user to do another.

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

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago