import java.util.Date; import java.util.Calendar; public abstract class Animal {
ID: 3708124 • Letter: I
Question
import java.util.Date;
import java.util.Calendar;
public abstract class Animal {
private static int id = 0;
private int age;
private int Id;
private String description;
private String name;
private Date arrival;
private Date adoption;
public Animal()
{
this("","", 0,0);
}
public Animal(String description)
{
this("",description,0,0);
}
public Animal (String name, String description, int age, int id)
{
id = id;
id++;
this.id = id;
this.name = name;
this.description = description;
this.age = age;
arrival = Calendar.getInstance().getTime();
adoption = Calendar.getInstance().getTime();
}
public Animal(Animal copyAnimal)
{
id = copyAnimal.id;
age = copyAnimal.age;
name = copyAnimal.name;
description = copyAnimal.description;
arrival = copyAnimal.arrival;
adoption = copyAnimal.adoption;
}
//setters and getters
public void setId(int id){
this.id = id;
}
public int getId() {
return this.id;
}
public void setName(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description){
this.description = description;
}
public String getDescription() {
return description;
}
public void setAge(int age){
this.age = age;
}
public int getAge() {
return age;
}
//equals and toString
public boolean equals(Animal testAnimal){
boolean match = false;
if (this.id == testAnimal.id
&& this.age == testAnimal.age
&& this.description.equals(testAnimal.description)
&& this.name.equals(testAnimal.name)
&& this.adoption.equals(testAnimal.adoption)
&& this.arrival.equals(testAnimal.arrival))
{
match = true;
}
return match;
}
public String toString() {
return " Id " + id
+" Age " + age
+" Name " + name
+" Description " + description
+" Arrival " + arrival
+" Adoption " + adoption;
}
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
public class Cat extends Animal
{
private String breed;
private String gender;
public String Cat(String name, int age, String description, String gender, String breed)
{
super(name,age,description);
this.breed = breed;
this.gender = gender;
}
public Cat()
{
this("","",0,0);
}
public Cat(Cat cat)
{
super(cat);
breed = cat.breed;
gender = cat.gender;
}
public boolean equals(Cat testAnimal){
boolean match = false;
if (super.equals(testAnimal)
&& breed == testAnimal.breed
&& gender == testAnimal.gender)
match = true;
return match;
}
public String toString()
{
return super.toString()
+ " Breed " + breed
+ " Gender " + gender;
}
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
public class Dog extends Animal
{
private String breed;
private String gender;
public String Dog(String name, int age, String description, String gender, String breed)
{
super(name,age,description);
this.breed = breed;
this.gender = gender;
}
public Dog()
{
this("","",0,0);
}
public Dog(Dog dog)
{
super(dog);
breed = dog.breed;
gender = dog.gender;
}
public boolean equals(Dog testAnimal){
boolean match = false;
if (super.equals(testAnimal)
&& breed == testAnimal.breed
&& gender == testAnimal.gender)
match = true;
return match;
}
public String toString()
{
return super.toString()
+ " Breed " + breed
+ " Gender " + gender;
}
}
can you write the javaDocs for these?
Explanation / Answer
/*****************************Animal.java***************************/
import java.util.Calendar;
import java.util.Date;
/**
* The Class Animal.
*/
public abstract class Animal {
/** The id. */
private static int id = 0;
/** The age. */
private int age;
/** The Id. */
private int Id;
/** The description. */
private String description;
/** The name. */
private String name;
/** The arrival. */
private Date arrival;
/** The adoption. */
private Date adoption;
/**
* Instantiates a new animal.
*/
public Animal() {
this("", "", 0, 0);
}
/**
* Instantiates a new animal.
*
* @param description
* the description
*/
public Animal(String description) {
this("", description, 0, 0);
}
/**
* Instantiates a new animal.
*
* @param name
* the name
* @param description
* the description
* @param age
* the age
* @param id
* the id
*/
public Animal(String name, String description, int age, int id) {
id = id;
id++;
this.id = id;
this.name = name;
this.description = description;
this.age = age;
arrival = Calendar.getInstance().getTime();
adoption = Calendar.getInstance().getTime();
}
/**
* Instantiates a new animal.
*
* @param copyAnimal
* the copy animal
*/
public Animal(Animal copyAnimal) {
id = copyAnimal.id;
age = copyAnimal.age;
name = copyAnimal.name;
description = copyAnimal.description;
arrival = copyAnimal.arrival;
adoption = copyAnimal.adoption;
}
/**
* Sets the id.
*
* @param id
* the new id
*/
// setters and getters
public void setId(int id) {
this.id = id;
}
/**
* Gets the id.
*
* @return the id
*/
public int getId() {
return this.id;
}
/**
* Sets the name.
*
* @param name
* the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the description.
*
* @param description
* the new description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets the age.
*
* @param age
* the new age
*/
public void setAge(int age) {
this.age = age;
}
/**
* Gets the age.
*
* @return the age
*/
public int getAge() {
return age;
}
// equals and toString
/**
* Equals.
*
* @param testAnimal
* the test animal
* @return true, if successful
*/
public boolean equals(Animal testAnimal) {
boolean match = false;
if (this.id == testAnimal.id && this.age == testAnimal.age && this.description.equals(testAnimal.description)
&& this.name.equals(testAnimal.name) && this.adoption.equals(testAnimal.adoption)
&& this.arrival.equals(testAnimal.arrival)) {
match = true;
}
return match;
}
public String toString() {
return " Id " + id + " Age " + age + " Name " + name + " Description " + description + " Arrival "
+ arrival + " Adoption " + adoption;
}
}
/***********************Cat.java*******************************/
/**
* The Class Cat.
*/
public class Cat extends Animal {
/** The breed. */
private String breed;
/** The gender. */
private String gender;
/**
* Instantiates a new cat.
*
* @param name
* the name
* @param age
* the age
* @param description
* the description
* @param gender
* the gender
* @param breed
* the breed
*/
public Cat(String name, int age, String description, String gender, String breed) {
super(name, age, description);
this.breed = breed;
this.gender = gender;
}
/**
* Instantiates a new cat.
*/
public Cat() {
this("", "", 0, 0);
}
/**
* Instantiates a new cat.
*
* @param cat
* the cat
*/
public Cat(Cat cat) {
super(cat);
breed = cat.breed;
gender = cat.gender;
}
/**
* Equals.
*
* @param testAnimal
* the test animal
* @return true, if successful
*/
public boolean equals(Cat testAnimal) {
boolean match = false;
if (super.equals(testAnimal) && breed == testAnimal.breed && gender == testAnimal.gender)
match = true;
return match;
}
public String toString() {
return super.toString() + " Breed " + breed + " Gender " + gender;
}
}
/**********************Dog.java*************************/
/**
* The Class Dog.
*/
public class Dog extends Animal {
/** The breed. */
private String breed;
/** The gender. */
private String gender;
/**
* Dog.
*
* @param name
* the name
* @param age
* the age
* @param description
* the description
* @param gender
* the gender
* @param breed
* the breed
* @return the string
*/
public Dog(String name, int age, String description, String gender, String breed) {
super(name, age, description);
this.breed = breed;
this.gender = gender;
}
/**
* Instantiates a new dog.
*/
public Dog() {
this("", "", 0, 0);
}
/**
* Instantiates a new dog.
*
* @param dog
* the dog
*/
public Dog(Dog dog) {
super(dog);
breed = dog.breed;
gender = dog.gender;
}
/**
* Equals.
*
* @param testAnimal
* the test animal
* @return true, if successful
*/
public boolean equals(Dog testAnimal) {
boolean match = false;
if (super.equals(testAnimal) && breed == testAnimal.breed && gender == testAnimal.gender)
match = true;
return match;
}
public String toString() {
return super.toString() + " Breed " + breed + " Gender " + gender;
}
}
Thanks a lot, Please let me know if you have any problem...............
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.