Anda di halaman 1dari 1

Chemical Engineering CHG 4343

Tutorial 4: Inheritance, Abstract Classes and Interfaces

This problem will make use of 6 classes (Species, Stream, RateConstant, HasRoot, Rootfinder, and
Tutorial4Main) that have been made already from the .zip file called 2016-10-31 Tutorial 4. Ensure you unzip
the files and open them in Dr. Java before proceeding.
The goal is to develop a set of classes which can calculate and return the reaction rate, given a certain set of
gaseous stream conditions. The following reactions will be considered in the presence of an inert gas :
+ 1 = 1 [][] [1]
+ 2 = 2 [][] 2 [] [2]

1) First, we want to find out at which temperature will the total concentration be 340 mol/m3. We have forgotten
about the ideal gas law, but we do have the interface HasRoot and a RootFinder. Well edit the Stream class so
that it implements HasRoot and add in the required method public double findXgivenY(double x,
double y). This method will first store a local value of the current stream temperature, this.T_i, then set the
instance variable T_i to the value x. It will then store the difference between y and the value of this.getC_t().
Before returning this value, it will restore the instance variable T_i to the value at the beginning of the method.
Now, in the main method from Tutorial4Main, call the RootFinder method bisectionRoot with the following
parameters:
RootFinder.bisectionRoot(0.1 /*min temp*/,10000 /*max temp*/, 340 /*target
concentration*/, 0.00005/*tolerance*/,1000 /*max iterations*/, mixture /*The stream
object, which is seen as a HasRoot object*/);
Print this value to the screen and use the Stream mutator method to update the temperature to this value.

2) Now define an abstract class called ReactionRate which will have three protected instance variables: a
RateConstant object, an array of type Species[], and an array of type double[] which will store the reaction
coefficients for each species (positive for products, negative for reactants). Create the necessary constructor, but
do not create the accessors and mutators for the sake of time (Try at home! Dont forget deep copying for the arrays
but for now, you can ignore the security leak of copying the user-defined objects).
Create an abstract method calcRxnRate(Stream mixture) that will return a double value.
3) Now create a sub class called ReactionRate1 that extends ReactionRate which will have a constructor that
calls the super constructor. It will have a concrete instance of the calcRxnRate(Stream mixture) method
which will calculate and return the reaction rate at the given stream conditions using equation 1) above
Note: using the Stream class, you can access concentration of component i using the getC_t()*gety()[i]
methods from the Stream object. You can also get the stream temperature with getT_i() to send to the
RateConstant objects method calcRateConstant.
(At home, or if we have time): Copy this class into another class called ReactionRate2. Add an extra private
instance variable for the reverse rate constant from equation 2). Include this instance variable in the constructor
method, and create the accessor and mutator methods for this object. Modify the calcRxnRate(Stream
mixture) method to match equation 2).
4) In the main method from the class Tutorial4Main, create the two double arrays which are the reaction
coefficients based on Equations 1) and 2).
Lastly, create the two objects for ReactionRate1 and ReactionRate2 (if we had time), sending them the
required rate constants, Species array, and reaction coefficients double array.
Print to the console the value of each reaction rate given the Stream object called mixture.

David G. Taylor, 2016 1 of 2

Anda mungkin juga menyukai