CreateabaseclasscalledAnimalwhichhas2classfields.ThefirstfieldholdsanintegerIDtagfora numberthatazoousestocataloguetheiranimals&thesecondfieldholdsastringcalledspecies. FromtheAnimalclass,derive2classesOneisBird&theotherReptile.Birdclasshasanadditional classfieldcalledcolourwhichholdsthe colour of the birds feathers(int – 1=grey, 2=white, 3=black).reptile class has an additional class field called bloodTemp which hold the reptiles temperature of their blood (double).You need to instantiate two 2 objects.bird object will be called brd.reptile object called rept.Input values for the bird’s IDtag,species & feather colour(int) & for the reptile’s IDtag number,species & bloodTemp.Override the Animal class’s input & output methods.Each derived class must have its own constructor.Write methods to input & output values to the class fields for all classes & then print out the values of the bird & reptile class fields with labels identifying the values.
public class Animal {
private int ID;
private String species;
public Animal(int id, String s) {
this.ID = id;
this.species = s;
}
public void setID(int id) {
this.ID = id;
}
public void setS(String s) {
this.species = s;
}
public int getID() { return ID; {
public String getSpecies() { return species; }
}
class Bird extends Animal {
public Bird(int id, String s) {
super(id, s);
}
}
class Reptile extends Animal {
public Reptile(int id, String s) {
super(id, s);
}
}
Comments
Leave a comment