I am having problemtrouble designing a module( I also think that this Module, can test skill of design pattern usage as it will be hard to mainatin this kind of module).Can anybody help me
Requirement:
This is basically an agricultural project (web application).I need to design module where some calcuation takes place.
There are differnt crops invovled like maize,tomato,okra etc.Now each of these crops have different traits.
Each trait has a mesurament scale which lies in integer like 200-1000.now let say i have planted the crop and
done measurement noted down the traits.Now i want to do some sort of measurement.Some measurements are simple and some are
complex.
Lets take an example of crop maize.I have recored observations for 15 trait.(trait1.. trait15 are just alias the acutal name can be like plt_ht,yld)
trait1 trait2 trait3 trait4 trait5 trait6..... trait15
i have recorded 5 observations for each traits
trait1 trait2 trait3 trait5 trait6..... trait15
01,02,03,04 01,02,03,04 01,02,03,04
User logs into system and selects his crops and enters data for these observation i either have to calculate average of those data entered for each or sum of those.
This is simple but complexity comes when for some of the tratis i have some different formulas. Like lets take an example let say a trait YLD has a formula based on which i have to caluate its value which may also depends on some other traits .This way all differnet crops have different traits.All this i am able to do whenever user selects crop i will check for those specific traits and do calculations if it is not special trait then i eaither avg it or sum it based on db entery but there is lot of hard coding .I want to have some suggestion from you people if u can think of an better way of handling this.?
Now my code has calcuate simple calcuation and complex calculations.Simple calucation are easy i have take average of vavlue enterd for trait, but problem comes when i have complex calcuation,since each crop have differnt traits which have complex calculations , i have to check for crop then for complex trait and then calculate .So i haveBecause it will be hard to hardcode the trait namemaintain this kind of complex traits .can any tell me howmodule, I also think that this can itest my skill of design usign java oops so that i make genericpattern usage.
#Requirement
This is basically an agricultural project (web application). I have about 10need to design a module where some calculation takes place.
There are different crops involved like maize, tomato, okra etc. Each of these crops has different traits.
Each trait has a measurement scale which lies in integer like 200-1000. Now let's say I have planted the crop and done measurement noted down the traits. Now I want to do some calcuationsort of measurement. Some measurements are specific to crops there will be lotsimple and some are complex.
Example
Lets take an example of codecrop maize. I have recorded observations for 15 traits. (We'll use trait1-trait15 as examples, the actual name can be like if below;plt_ht, yld, etc.)
I recorded 5 observations for each trait:
trait1 trait2 trait3 trait5 trait6..... trait15
01,02,03,04 01,02,03,04 01,02,03,04
User logs into system and selects his crops and enters data for these observations. I have to calculate either average or sum of the data entered for each trait.
Complexity / centre of the problem
So far it's simple but complexity comes when I have some different formulas for some of the traits.
Example: trait YLD has a formula based on which I have to calculate its value, which may also depend on some other traits. Each different crop can have different traits.
All this I am able to do - whenever user selects crop I will check for those specific traits and do calculations (if it's not a special trait then I either average or sum it, based on db entry), but there is a lot of hard coding.
I would like to have suggestions on a better way of handling this.
My code needs to handle both simple and complex calculations.
Simple calculations are easy, I have take average of value entered for trait.
The problem comes when I have to do complex calculations, since each crop have different traits with their own formulas, so to calculate I have to check for crop and then for complex trait. So I have to hardcode the trait name of complex traits.
Can any tell me how I can design this using Java oops [?!?] so that I can make it generic?
I have about 10 different crops. Some calculations are specific to crops, so there will be lot of code like the if
below:
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("MZ") && traitName.equalsIgnoreCase("Shelling")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPoint, dataTraits, traitValues,dataPvalues, dataPoint, type);
avg=avg*dataPoint;
traitAvg=getMaizeYeild(traitName, traitAvg, population, avg, hybrid, area);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YLDGM")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPoint, dataTraits, traitValues,dataPvalues, dataPoint, type);
//avg=avg*dataPoint;
Object[] dataValues=getOKRAYield(traitName, traitAvg, population, avg, dividend,hasZeroValue,hybrid,repl);
traitAvg = (HashMap<String, Float>) dataValues[0];
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("HP") && traitName.equalsIgnoreCase("w1-w10")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPts, dataTraits, traitValues,dataPvalues, dataPoint, type);
avg=avg*dataPoint;
Object[] dataValues=getHotPepperYield(traitName, traitAvg, population, avg,dividend,hasZeroValue,hybrid,repl);
traitAvg = (HashMap<String, Float>) dataValues[0];
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("TLSSG_70")) {
traitAvg=calculateTLCV(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues,50);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("TLSSG_100")) {
traitAvg=calculateTLCV(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues,50);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg, dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("ELCV_60")) {
I want to have generic solution ifCan anybody can think of a way to make a generic approach to this?