Question
import java.time.LocalDate; public class Dog { private final String name; private final Breed breed; private final LocalDate dateOfBirth; private final LocalDate dateOfDeath; public Dog(String name,
import java.time.LocalDate;
public class Dog { private final String name; private final Breed breed; private final LocalDate dateOfBirth; private final LocalDate dateOfDeath;
public Dog(String name, Breed breed, LocalDate dateOfBirth, LocalDate dateOfDeath) { this.name = name; this.breed = breed; this.dateOfBirth = dateOfBirth; this.dateOfDeath = dateOfDeath; } public static class Breed { private final String name; private final String origin;
public Breed(String name, String origin) { this.name = name; this.origin = origin; }
public String toString() { return name + "(" + origin + ")"; } }
public boolean isAlive() { return dateOfDeath == null || dateOfDeath.isAfter(LocalDate.now()); }
public String toString() { return "Name: " + name + ", Breed: " + breed.toString() + ", Date of Birth: " + dateOfBirth + ", Date of Death: " + dateOfDeath; }
public static void main(String[] args) { Breed breed = new Breed("Alaskan Malamute","Virginia"); LocalDate dob = LocalDate.of(2018, 5, 15); Dog dog = new Dog("Deuce", breed, dob, null); System.out.println("Dog Name: " + dog.name); System.out.println("Dog Breed: " + dog.breed); System.out.println("Dog's Date of Birth: " + dog.dateOfBirth); System.out.println("Is dog alive: " + dog.isAlive());
} } In this assignment I need help to
Override and implement the equals(..) method for the Dog class. We'll consider one dog to be equivalent to another dog if their names, age, and likesFetch fields match exactly.Override and implement hashCode() for the Dog class. The method should calculate and return the hash value computed from the name, age, and likesFetch fields. Create a Tester class containing a main(..) method and instantiate three Dog objects named d1, d2, and d3. Instantiate the objects such that d1.equals(d2) but neither d1 nor d2 equal d3 in the lab above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started