java.util.Date birthDate and the following public instance methods: toString: Returns the animal’s vegetarian, eatings, numOfLegs AND birthDate information as a string    The Cat class should also have  override toString: Returns the cat’s vegetarian, eatings, numOfLegs, birthDate and color information as a string  can you please explain to me why Animal.java class's "set" method doesn't assign an argument of type java.util.Date to birthDate as well as why Animal.java class doesn't have a "get" method for birthDate.   Animal.java

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The Animal class should  also have 

java.util.Date birthDate and the following public instance methods:

toString: Returns the animal’s vegetarian, eatings, numOfLegs AND birthDate information as a string 

 

The Cat class should also have 

override toString: Returns the cat’s vegetarian, eatings, numOfLegs, birthDate and color information as a string 

can you please explain to me why Animal.java class's "set" method doesn't assign an argument of type java.util.Date to birthDate as well as why Animal.java class doesn't have a "get" method for birthDate.  

Animal.java

class Animal
{
  
protected boolean vegetarian;
protected String eatings;
protected int numOfLegs;

public Animal()
{
   vegetarian = false;
   eatings = "meat";
   numOfLegs = 4;
}

public Animal(boolean vegetarian,String eatings, int numOfLegs)
{
   this.vegetarian = vegetarian;
   this.eatings = eatings;
   this.numOfLegs = numOfLegs;
}

public void SetAnimal(boolean vegetarian,String eatings, int numOfLegs)
{
   this.vegetarian = vegetarian;
   this.eatings = eatings;
   this.numOfLegs = numOfLegs;
  
}


public boolean getVegetarian()
{
   return vegetarian;
}
public String getEatings()
{
   return eatings;
}
public int getNumOfLegs()
{
   return numOfLegs;
}

public String toString()
{
return "Animal’s vegetarian : "+ vegetarian +", eatings : "+ eatings+" number of legs : "+numOfLegs;
}

}

Cat.java
class Cat extends Animal
{

private String color;
public Cat()
{
   super();
}

public Cat(boolean vegetarian,String eatings, int numOfLegs, String color)
{
super(vegetarian,eatings,numOfLegs);
this.color = color;
}


public void SetColor(String color)
{
   this.color = color;
}

public String GetColor()
{
   return color;
}

public String toString()
{
   return super.toString() +" color : "+color;
}

}

 

class testAnimal
{
   public static void main (String[] args)
   {
     
       Cat e1 = new Cat();
       Cat e2 = new Cat(false,"meat,milk",4, "white");
      
       e1.SetAnimal(true,"grass",4);

e1.SetColor("black");
      
       System.out.println(e1);
       System.out.println(e2);
      
   }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education