Results 1 to 3 of 3
Thread: return a null method
- 04-16-2008, 09:20 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
return a null method
this is my method that returns a null but that is not a good thing to return coz my program will fail...what can I do to return a sum thing that will cause my program not to throw a nullpointer exception...here is my code
Java Code:private MgCalcStrategy getStrategy() { if (isRetirementScheme && isAdminInclusive) { return MgCalcStrategy.RET_INCLUSIVE; } if (isRetirementScheme && !isAdminInclusive) { return MgCalcStrategy.RET_EXCLUSIVE; } if (isBothScheme && isAdminInclusive && isRiskInclusive) { return MgCalcStrategy.RISK_INC_ADMIN_INC; } if (isBothScheme && isAdminInclusive && !isRiskInclusive) { return MgCalcStrategy.RISK_INC_ADMIN_INC; } if (isBothScheme && !isAdminInclusive && isRiskInclusive) { return MgCalcStrategy.RISK_INC_ADMIN_EXC; } if (isBothScheme && !isAdminInclusive && !isRiskInclusive) { return MgCalcStrategy.RISK_EXC_ADMIN_EXC; } if (isRiskScheme) { return MgCalcStrategy.RISK_ONLY; } //TODO: Change this to return a null Strategy return null; }
- 04-16-2008, 10:43 AM #2
I guess your code must return an object....
Have a look at object class, take a comparison with null....
if satisfied, then block, else allow...
Correct me if im wrong,
sukatoa
- 04-21-2008, 11:19 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
just don't know how am I gona implement the null strategy...here is the completing code of what I have ...please help mepublic enum MgCalcStrategy {
RET_INCLUSIVE {
public double getCost(MemberGroup mg,Quote quote) {
return mg.getEeContribPerc() + mg.getErContribPerc()/PERCENT_VALUE
* mg.getTotalAnnualSalary();
}
},
RISK_INC_ADMIN_EXC {
public double getCost(MemberGroup mg,Quote quote) {
return (mg.getEeContribPerc() + mg.getErContribPerc()
+ mg.getBenefitFam().getPercCost() + quote.getFinalInput().getAdminPerc()
+ quote.getFinalInput().getRenewalCommPerc())
/PERCENT_VALUE * mg.getTotalAnnualSalary();
}
},
RiskExcAdminInc {
public double getCost(MemberGroup mg,Quote quote) {
return mg.getEeContribPerc()+ mg.getErContribPerc() ;
}
},
RISK_EXC_ADMIN_EXC{
public double getCost(MemberGroup mg,Quote quote) {
return mg.getErContribPerc()+ mg.getEeContribPerc()+
quote.getFinalInput().getAdminPerc()+
quote.getFinalInput().getRenewalCommPerc()+
mg.getBenefitFam().getPercCost()/PERCENT_VALUE
* mg.getTotalAnnualSalary();
}
},
RiskOnly {
public double getCost(MemberGroup mg,Quote quote) {
return mg.getBenefitFam().getPercCost();
}
}, ;
public abstract double getCost(MemberGroup mg,Quote quote);
private static final double PERCENT_VALUE = 100.0;
}
Similar Threads
-
Error: invalid method declaration; return type required
By silvia in forum AWT / SwingReplies: 3Last Post: 06-05-2010, 08:05 PM -
return Set .toArray(); method as an array of integers
By maxim in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:35 PM -
Return question in a method.
By MetalGear in forum New To JavaReplies: 1Last Post: 01-13-2008, 04:45 AM -
if..else..return
By mqdias in forum New To JavaReplies: 1Last Post: 08-10-2007, 04:20 PM -
Return value of method
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks