Create java class with name Dog.
Instructions for Dog class:
This class is modeled after a Dog. You should have instance variables as follows:
*: For the Dog’s fur color you should use the Color class from the java.awt package.
You should choose proper types and meaningful identifiers for each of these instance variables.
Your class should contain two constructor methods. A default constructor and a constructor that allows you to instantiate an object of the Dog class and choose initial values for each of the three instance variables.
Your class should also contain accessor methods for all three instance variables. However, you should onlyhave a mutator method to change the number of tricks known by the Dog (it would be mean to change its name or the color of its fur).
You will also need to override the toString method to work properly for the class. It should return a String containing the dog’s name, the number of tricks it can perform, and its coat color.
import java.awt.*; public class Dog { private String name; private int numTricks; private Color colorCoat; public Dog() { } public Dog(String name, int numTricks, Color colorCoat) { this.name = name; this.numTricks = numTricks; this.colorCoat = colorCoat; } public String getName() { return name; } public int getNumTricks() { return numTricks; } public void setNumTricks(int numTricks) { this.numTricks = numTricks; } public Color getColorCoat() { return colorCoat; } public String toString() { return "name='" + name + '\'' + ", numTricks=" + numTricks + ", colorCoat=" + colorCoat; } }
Get Answers For Free
Most questions answered within 1 hours.