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

Please help with this Java code. Here is the problem: Human Class beAPig method

ID: 3740737 • Letter: P

Question

Please help with this Java code. Here is the problem:

Human Class

beAPig method

input: boolean pigness

output: boolean value of pigness

Algorithm: sets the value of the pigness varible to the input parameter and returns the same value.  

Also I am not sure on my bottem code? I left a few comments.

My UML was:

Human

No Variables

+ Computer(name: String) ; constructor

+ beAPig(isPig: boolean) : boolean

//*********************************************************************

//

//

//*********************************************************************

public class Human

{

//-----------------------------------------------------------------

// Constructor

//-----------------------------------------------------------------

public Human(String name)

{

this.name = name; // Is this right????

}

//-----------------------------------------------------------------

//

//-----------------------------------------------------------------

public boolean beAPig(boolean isPig)

{

return isPig; // not sure if this is right?????

}

}

Explanation / Answer

//*********************************************************************

//

//

//*********************************************************************

public class Human

{

//-----------------------------------------------------------------

// Constructor

//-----------------------------------------------------------------

public Human(String name)

{

// this is correct

this.name = name; // Is this right????

}

//-----------------------------------------------------------------

//

//-----------------------------------------------------------------

    public boolean beAPig(boolean isPig)

    {

        // sets the value of the pigness varible to the input parameter

        this.pigness = isPig;

       

        // returns the same value.

        return isPig; // not sure if this is right?????

    }

}