Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This portion of code is looking to see if there is a premium increase or decreas

ID: 3603791 • Letter: T

Question

This portion of code is looking to see if there is a premium increase or decrease depending on certain factors. Some factors are liabilities like smoking, high risk status, or poor health. Some are assets, like non-smoker, good health and low risk status.

It is asking us to write certain criteria then assign either asset or liability, At the end, we need code that says if there are 3 or more assets, then subtract 15.00 from premium. If there are 3 or more liabilities, then add 65.00 to the premium.

I keep getting the error "Missing Return Statement" at the end of the code and can't figure out why. Can anyone provide some help?

/**

     * Calculate demographics-related rate adjustment.

     *

     * @param   inSmoker        whether or not candidate is a smoker.

     * @param   inAge           age of candidate.

     * @param   inHighRisk      whether or not candidate is high risk.

     * @param   inNumTickets    number of traffic tickets for candidate.

     * @param   inHealth        candidate health status (Good, Fair, Poor).

     * @return double          monthly premium adjustment.

     *

     */

   

public static double calcDemogAdj(int inAge, boolean inSmoker,

boolean inHighRisk, int inNumTickets, String inHealth)

    {

        // Variable to count factors that contribute to premium decrease

        int asset = 0;

        // Variable to count factors that contribute to premium increase

        int liability = 0;

        // Variable to hold rate adjustment

        double rateAdjustment = 0;

        // Determine if demographic data counts toward increase/decrease

        if (inAge < 25)

        {

            ++asset;

        }

        if (inSmoker)

       {

            ++liability;

        }

        else

        {

            ++asset;

        }

        if (inHighRisk)

        {

            ++liability;

        }

        else

        {

            ++asset;

        }

        if (inHealth == "Poor")

        {

            ++liability;

        }

        if (inHealth == "Good")

        {

            ++asset;

        }

        if (inNumTickets == 0)

        {

            ++asset;

        }

        if (inNumTickets == 3)

        {

            ++liability;

        }

        // were there enough factors to decrease premium?

        if (asset >= 3)

        {

            rateAdjustment = -15.00;

        }

        if (liability >= 3)

        {

            rateAdjustment = 65.00;

        }

    } Says Missing Return Statement

}

Explanation / Answer

Hi, yes I can help you on that.

See, the method signature is:

public static double calcDemogAdj(int inAge, boolean inSmoker, boolean inHighRisk, int inNumTickets, String inHealth)

> The double here indicates that this method would return a value of type double, and your method was not returning anything; hence, it was showing the error. The correct code for it will be as below:

public static double calcDemogAdj(int inAge, boolean inSmoker, boolean inHighRisk, int inNumTickets, String inHealth)

{

// Variable to count factors that contribute to premium decrease

int asset = 0;

// Variable to count factors that contribute to premium increase

int liability = 0;

// Variable to hold rate adjustment

double rateAdjustment = 0;

// Determine if demographic data counts toward increase/decrease

if (inAge < 25)

{

++asset;

}

if (inSmoker)

{

++liability;

}

else

{

++asset;

}

if (inHighRisk)

{

++liability;

}

else

{

++asset;

}

if (inHealth == "Poor")

{

++liability;

}

if (inHealth == "Good")

{

++asset;

}

if (inNumTickets == 0)

{

++asset;

}

if (inNumTickets == 3)

{

++liability;

}

// were there enough factors to decrease premium?

if (asset >= 3)

{

rateAdjustment = -15.00;

}

if (liability >= 3)

{

rateAdjustment = 65.00;

}

  

return rateAdjustment;

}

If you don't want your method to return anything, then in that case, the return type should be void! Kindly let me know if you have any doubts regarding this!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote