Question: Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in Section 5.2. The new version should include accessor
Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in Section 5.2. The new version should include accessor and mutator methods. Also define an equals method for the class that returns true if the dog’s name, age, and breed match the same variables for the other object that is being compared. Include a main method to test the functionality of the new Dog class.
Listing 5.1

public class Dog { public String name; public String breed; public int age; public void writeOutput () { System.out.printin("Name: " + name); System.out.println("Breed: " + breed); System.out.println("Age in calendar years: Later in this chapter we will see that the modifier public for instance variables should be replaced with private. age); System.out.println("Age in human years: getAgeInHumanYears ()); %3D + System.out.printin(); } public int getAgeInHumanYears () { int humanAge if (age
Step by Step Solution
3.34 Rating (166 Votes )
There are 3 Steps involved in it
public class Dog private String name private String breed private int age Accessors an... View full answer
Get step-by-step solutions from verified subject matter experts
