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

I can\'t figure out why I\'m getting docked points on this. I am given the follo

ID: 3604083 • Letter: I

Question

I can't figure out why I'm getting docked points on this. I am given the following hint:

* Hint: health value not null as expected by default constructor

The first code is the constructor and the second code is my test case. What am I doing wrong when I write the code to test the health value?

/**

     * First constructor for objects of class RateEstimator.

     */

    public RateEstimator()

    {

        this.smoker = false;

        this.gender = ' ';

        this.age = 0;

        this.highRisk = false;

        this.numTickets = 0;

        this.health = "Null";

    }

/**

     * Test constructor #1.

     */

    @Test

    public void testConstructor1()

    {

        RateEstimator rateTest = new RateEstimator();

        assertNotNull(rateTest);

        // check smoker attribute value

        assertFalse(rateTest.isSmoker());

        // check gender attribute value

        assertEquals(' ', rateTest.getGender());

        // check age attribute value

        assertEquals(0, rateTest.getAge());

        // check high risk attribute value

        assertFalse(rateTest.isHighRisk());

        // check number of tickets attribute value

        assertEquals(0, rateTest.getNumTickets());

        // check health attribute value

        assertEquals("Null", rateTest.getHealth());

Explanation / Answer

For null, It should be without quotes because null is a keyword in Java. Try it out and let me know if you face any issue. We can try someothing out as well to make it work, Comment and I will surely respond

/**

     * First constructor for objects of class RateEstimator.

     */

    public RateEstimator()

    {

        this.smoker = false;

        this.gender = ' ';

        this.age = 0;

        this.highRisk = false;

        this.numTickets = 0;

        this.health = null;

    }

/**

     * Test constructor #1.

     */

    @Test

    public void testConstructor1()

    {

        RateEstimator rateTest = new RateEstimator();

        assertNotNull(rateTest);

        // check smoker attribute value

        assertFalse(rateTest.isSmoker());

        // check gender attribute value

        assertEquals(' ', rateTest.getGender());

        // check age attribute value

        assertEquals(0, rateTest.getAge());

        // check high risk attribute value

        assertFalse(rateTest.isHighRisk());

        // check number of tickets attribute value

        assertEquals(0, rateTest.getNumTickets());

        // check health attribute value

        assertEquals(null, rateTest.getHealth());

}

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