Question: Java please! Part 2 . public class Animal { private String name; private int age; private String species; private boolean canFly; public Animal(String name, int
Java please! Part 2 .
public class Animal {
private String name; private int age; private String species; private boolean canFly;
public Animal(String name, int age, String species, boolean canFly) { super(); this.name = name; this.age = age; this.species = species; this.canFly = canFly; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getSpecies() { return species; }
public void setSpecies(String species) { this.species = species; }
public boolean isCanFly() { return canFly; }
public void setCanFly(boolean canFly) { this.canFly = canFly; }
public String toString() { return "Animal [name=" + name + ", age=" + age + ", species=" + species + ", canFly=" + canFly + "]"; }
}

1. Define a class: Class: Animal Data fields: name: String age: int species: String // example: canFly: boolean Methods: Constructor All setter/getter methods to get or set a data field/member. toString(): String // return information of an animal object 2. Test (a) Define an Animal array. (b) Create the following animal instances: cat, dog, bird, dog, deer. Add them into array. (c) Define a method to search into an Animal array to find animals of a specific specie, return animals of that species. (d) Call method defined in (c) to search for dog animals in the array defined in (a). Display information of those dogs returned from the method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
