Is this method a mutator or accessor method?

I have the below method which returns true if a growth rate is less than 0 or false otherwise. I was wondering what kind of method it would be, mutator or accessor.

    public boolean endangered(double GR) {
    if (GR < 0) {
        return true;
    } else {
        return false;
    }
}

It does not access or mutate any value — its a new value that is being returned, it seems, and will possibly be used somewhere.

Below is the full class, if that helps:

public class Species {

    private int population;
    private double growthRATE;
    private String speciesName;
    private String endangered;

    public Species() {
        speciesName = "Dingo";
        population = 1000;
        growthRATE = 0.6;
    }

    public Species(String name, int population, double GR) {
        name = name;
        population = population;
        growthRATE = GR;
    }

    //Mutator methods

    //accessor methods


    public boolean endangered(double GR) {
        if (GR < 0) {
            return GR < 0;
        } else {
            return GR < 0;
        }
    }
}

Answer

None of them. You doesn’t mutate any instance and you don’t return a field instance either.
Your method makes some logic, so you could say that it is a logic/business method.

Leave a Reply

Your email address will not be published. Required fields are marked *