Answer:
Dog.java:
Dog{
//Declare instance variables
private String name;
private int age;
//Create the constructor with two parameters, and initialize the instance variables
public Dog(String name, int age){
this.name = name;
this.age = age;
}
//get methods
public String getName(){
return name;
}
public int getAge(){
return age;
}
//set methods
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
//calculateAgeInPersonYears() method to calculate the age in person years by multiplying the age by 7
public int calculateAgeInPersonYears(){
return 7 * getAge();
}
//toString method to return the description of the dog
public String toString(){
return "Name: " + getName() + ", Age: " + getAge() + ", Age in Person Years: " + calculateAgeInPersonYears();
}
}
Kennel.java:
public class Kennel
{
public static void main(String[] args) {
//Create two dog objects using the constructor
Dog dog1 = new Dog("Dog1", 2);
Dog dog2 = new Dog("Dog2", 5);
//Print their information using the toString method
System.out.println(dog1.toString());
System.out.println(dog2.toString());
//Update the first dog's name using setName method
dog1.setName("Doggy");
System.out.println(dog1.toString());
//Update the second dog's age using setAge method
dog2.setAge(1);
System.out.println(dog2.toString());
}
}
Step-by-step explanation:
*The code is in Java.
You may see the explanations as comments in the code