A.Create a class called Dog that represents a dog. The class should have fields
ID: 3822210 • Letter: A
Question
A.Create a class called Dog that represents a dog. The class should have fields representing the dog's name, age, and breed. Add two constructors to the class: 1) a no parameter constructor that sets the following as default values -- name: Spot, age: 1, breed: retriever and 2) a constructor that takes parameters for each field. Your class should not contain any other fields or methods at this point.
B.Using your design and implementation of the above Dog class, add appropriate accessor and mutator methods to the class. (You do not have to retype the entire class, just type out the new methods requested.)
Explanation / Answer
Dog.java
public class Dog {
private String name, breed;
private int age;
public Dog() {
name = "Spot";
age = 1;
breed = "retriever ";
}
public Dog(String name, int age, String breed) {
this.name = name;
this.age = age;
this.breed = breed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBreed() {
return breed;
}
public void setBreed(String breed) {
this.breed = breed;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.