public class Reptile extends Animal { private String type; private String gender
ID: 3708123 • Letter: P
Question
public class Reptile extends Animal
{
private String type;
private String gender;
public String Reptile(String name, int age, String description, String gender, String type)
{
super(name,age,description);
this.type = type;
this.gender = gender;
}
public Reptile()
{
this("","",0,0);
}
public Reptile(Reptile reptile)
{
super(reptile);
type = reptile.type;
gender = reptile.gender;
}
public boolean equals(Reptile testAnimal){
boolean match = false;
if (super.equals(testAnimal)
&& type == testAnimal.type
&& gender == testAnimal.gender)
match = true;
return match;
}
public String toString()
{
return super.toString()
+ " Type " + type
+ " Gender " + gender;
}
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
public class TestAnimal
{
public static void main(String[] args)
{
Cat c1, c2, c3;
c1 = new Cat("Dr evil","persian",9,000);
c1 = new Cat(c1);
display(c1);
System.out.println(c2);
if (c1.equals(c2))
System.out.println("cat 1 == cat 2");
Animal a1 = new Cat(c1);
System.out.println(a1);
a1 = new Cat ("kitty","tammy",91,001);
System.out.println(a1);
}
public static void display (Animal animal)
{
System.out.println(animal);
{
Dog d1, d2, d3;
d1 = new Dog("rover","basset",13,001);
d1 = new Dog(d1);
display(d1);
System.out.println(d2);
if (d1.equals(d2))
System.out.println("dog 1 == dog 2");
Animal a2 = new Dog(d1);
System.out.println(a2);
a2 = new Dog ("rover2","basset",15,002);
System.out.println(a2);
}
{
System.out.println(animal);
{
Reptile r1, r2, r3;
r1 = new Reptile("snakey","snake",13,001);
r1 = new Reptile(r1);
display(r1);
System.out.println(r2);
if (r1.equals(r2))
System.out.println("Reptile 1 == Reptile 2");
Animal a3 = new Reptile(r1);
System.out.println(a3);
a3 = new Reptile ("fly catcher","iguana",25,004);
System.out.println(a3);
}
{
System.out.println(animal);
}
}
////////////////////////////////////////////
Can you write the javaDocs for these?
Explanation / Answer
public class Reptile extends Animal { private String type; private String gender; /** * Constructor with arguments to create a Reptile * * @param name of the reptile * @param age of the reptile * @param description of the reptile * @param gender of the reptile * @param type of the reptile */ public Reptile(String name, int age, String description, String gender, String type) { super(name,age,description); this.type = type; this.gender = gender; } /** * Constructor with no parameters to create a Reptile */ public Reptile() { this("","",0,0); } /** * Copy Constructor for Reptile * * @param reptile parameter to copy details from */ public Reptile(Reptile reptile) { super(reptile); type = reptile.type; gender = reptile.gender; } /** * Determines if two reptiles are equal * * @param testAnimal * @return true if two Reptiles have same type and gender */ public boolean equals(Reptile testAnimal){ boolean match = false; if (super.equals(testAnimal) && type == testAnimal.type && gender == testAnimal.gender) match = true; return match; } /** * * @return string representation of reptile object */ public String toString() { return super.toString() + " Type " + type + " Gender " + gender; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.