import java.util.ArrayList; /* * * CS161 Section 001 */ public class Pet { private static int id=0; // to create unique IDs for pets private String name; private double weight; private int myID; public Pet() { myID = ++id; name = ""; weight = 0; } public Pet(String n) { myID = ++id; name = n; weight = 0; } /* * Not all get methods are listed. Please practice your own. */ public double getWeight() { return weight; } /* * set method not provided for ID because that is not allowed to be changed. */ public void setWeight(double weight) { this.weight = weight; } public void setName(String name) { this.name = name; } public String toString() { return "ID: = " + myID + "; Name: " + name + "; Weight: " + weight; } /* * Suppose your notion of equality means that ID and name should match. * Note that ID's are supposedly unique, so it should be enough to match ID's. */ public boolean equals(Object o) { if(o instanceof Pet) { if (((Pet)o).myID == myID && ((Pet)o).name.equals(name)) // don't use == for name return true; } return false; } public static void main(String[] args) { Pet p1 = new Pet(); p1.setName("Nemo"); p1.setWeight(13.5); //System.out.println(p1); Pet p2 = new Pet("Loki"); p2.setWeight(3.7); //System.out.println(p2); Pet p3 = new Pet("Kitty"); p3.setWeight(10.1); Pet p4 = new Pet("Chloe"); p4.setWeight(5.1); Pet p5 = new Pet("Shadow"); p5.setWeight(7.8); ArrayList pets = new ArrayList(); pets.add(p1); pets.add(p2); pets.add(p3); pets.add(p4); pets.add(p5); System.out.println(pets); System.out.println(); System.out.println("Pets weight less than 7.0 lbs..."); // for(int i=0; i