Results 1 to 3 of 3
  1. #1
    valoyivd is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default 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;
        }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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

  3. #3
    valoyivd is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default

    public 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;

    }
    just don't know how am I gona implement the null strategy...here is the completing code of what I have ...please help me

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 09:05 PM
  2. Replies: 2
    Last Post: 04-16-2008, 01:35 PM
  3. Return question in a method.
    By MetalGear in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 05:45 AM
  4. if..else..return
    By mqdias in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 05:20 PM
  5. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •