In: Computer Science
Create a java class with name Cat.
Instructions for Cat class:
This class is modeled after a Cat. You should have instance variables as follows:
Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to kill you. Sometimes the plot is out in the open.
Your class should contain two constructor methods. A default constructor and a constructor that allows you to instantiate an object of the Cat class and choose initial values for each of the three instance variables.
Your class should also contain accessor and mutator methods for all three instance variables (Cat’s really don’t care what you call them, they won’t listen regardless, and it is potentially possible that it will stop plotting to kill you, although this is both unlikely and only temporary).
You will also need to override the toString method to work properly for the class. It should return a String containing the Cat’s name, the number of mice caught by the Cat, and whether or not the Cat is secretly plotting to kill you.
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks =========================================================================== public class Cat { private String catName; private int miceCaught; private boolean isAssassin; //A default constructor and a constructor that allows you // to instantiate an object of the Cat class and choose // initial values for each of the three instance variables. // default constructor public Cat() { this.catName = "Tammy"; this.miceCaught = 21; this.isAssassin = false; } // overloaded constructor public Cat(String catName, int miceCaught, boolean isAssassin) { this.catName = catName; this.miceCaught = miceCaught; this.isAssassin = isAssassin; } //mutator methods //Your class should also contain accessor and mutator methods for all three instance variables public String getCatName() { return catName; } public int getMiceCaught() { return miceCaught; } public boolean isAssassin() { return isAssassin; } // acccessor methods //Your class should also contain accessor and mutator methods for all three instance variables public void setCatName(String catName) { this.catName = catName; } public void setMiceCaught(int miceCaught) { this.miceCaught = miceCaught; } public void setAssassin(boolean assassin) { isAssassin = assassin; } //You will also need to override the toString method to work // properly for the class. It should return a String containing // the Cat’s name, the number of mice caught by the Cat, and whether // or not the Cat is secretly plotting to kill you. @Override public String toString() { if (isAssassin) return catName + ", caught " + miceCaught + " mice(s) and secretly plotting to kill you."; else return catName + ", caught " + miceCaught + " mice(s) and not secretly plotting to kill you."; } }