few more facts about farm animals:  Ruminants are a particular type of grazing mammal, in that Ruminants chew cud.  They also have multiple stomachs for digesting their forage.  Cows and goats have multiple stomachs and chew cud.  Horses graze but are not ruminants and do not chew cud and do not have multiple stomachs.  The concepts of Mammal, Grazing Mammal, and Ruminant are abstractions, that is, these words  are conceptual constructs.  You cannot go to a farm animal auction or Amazon and buy a Ruminant.  If you ask for one, the seller will ask you what kind? You must buy an actual, concrete, non-abstract animal such as a cow. goat, or horse.   For this reason, if we model Mammal, GrazingMammal, and Ruminant classes in Java, these classes are declared as abstract and cannot be instantiated (just like a ruminant cannot be born or bought). However, the characteristics and behavior of mammals, grazing mammals, and ruminants can be inherited by their descendants, as shown below.   Your job is to implement the following class design:

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

A few more facts about farm animals:  Ruminants are a particular type of grazing mammal, in that Ruminants chew cud.  They also have multiple stomachs for digesting their forage. 

Cows and goats have multiple stomachs and chew cud.  Horses graze but are not ruminants and do not chew cud and do not have multiple stomachs. 

The concepts of Mammal, Grazing Mammal, and Ruminant are abstractions, that is, these words  are conceptual constructs.  You cannot go to a farm animal auction or Amazon and buy a Ruminant.  If you ask for one, the seller will ask you what kind? You must buy an actual, concrete, non-abstract animal such as a cow. goat, or horse.   For this reason, if we model Mammal, GrazingMammal, and Ruminant classes in Java, these classes are declared as abstract and cannot be instantiated (just like a ruminant cannot be born or bought).

However, the characteristics and behavior of mammals, grazing mammals, and ruminants can be inherited by their descendants, as shown below.  

Your job is to implement the following class design:

  
All components of this exercise are provided in the instructions below.  You will just need to assemble the components as instructed.  To make this easier, you are provided below with a stubbed-out source code file listing only the declarations fo the classes that you need to populate with code.  

You may implement your project using either IntelliJ by creating a new project and adding this java file to your project, or adding a new class and pasting in the file below,  to your new class. 

You can download the empty java file GrazingMammals.java that you need to implement here.  

How to implement the GrazingMammals project:

  1.  Create an abstract class Mammal. As shown in the class diagram.  Mammal has one public method nursesYoung() that prints out “I am a “ + className + “. I am  nursing.”   You can get the class name from the instance of any class with the following:

String className = this.getClass().getSimpleName(); 

}

2. Create an interface RuminantTester..  The interface should contain two public methods. You can copy and paste these into the interface.

     void testIfRuminant();
    void  testHasMultipleStomachs();

3. Create an abstract class GrazingMammal similar to Mammal but which implements the method grazes().   This method should print out "I am a " + className + ". I am grazing.", similar to what we did with the Mammal class. 

GrazingMammal extends from Mammal and implements the interface RuminantTester.  

In order  to implement the interface you need to add the two methods in the interface to GrazingMammal.   These are provided here: 

     @Override
   public void testHasMultipleStomachs()  {
       String className = this.getClass().getName();
       if (this instanceof Ruminant)
          System.out.println("I am a " + className + ". I have multiple stomachs.");
      else
         System.out.println("I am a " + className + ". I do not have multiple stomachs.");
   }

    @Override
   public void testIfRuminant()  {
      String className = this.getClass().getName();
      if (this instanceof Ruminant )
         System.out.println("I am a " + className + ". I am a Ruminant.");
      else
         System.out.println("I am a " + className + ". I am not a Ruminant.");
     }

The @Override annotation indicates that we are replacing the interface stub method with a method body.  We can also override methods from an inherited class and this case also uses this annotation. 

4. Create an abstract class Ruminant that extends GrazingMammal.  Ruminant should print out "I am a " + className + ". I am chewing cud."), similar to the Mammal method implementation.

5.  Add the classes Cow and Goat, which extend Ruminant and add the class Horse which extends GrazingMammal.  These three classes are just class declarations with empty bodies, yet they provide all the behavior we need. 

mission.6.   A test driver class called GrazingMammals is proviided below,   Add this to your project file. 

public class TestMammals {
   public static void main(String[] args) {
       Cow cow = new Cow();
       cow.nursesYoung();
       cow.grazes();
       cow.chewsCud();
       cow.testIfRuminant();
       cow.testHasMultipleStomachs();
       System.out.println("\n");
       Goat goat = new Goat();
       goat.nursesYoung();
       goat.grazes();
       goat.chewsCud();
       goat.testIfRuminant();
       goat.testHasMultipleStomachs();
       System.out.println("\n");
       Horse horse  = new Horse();
       horse.nursesYoung();
       horse.grazes();
       horse.testIfRuminant();
       horse.testHasMultipleStomachs();
   }
}

Notes:   

  1.  All these classes can be included in a single code file named the same as the main class, in this case, GrazingMammals.java.  All other classes should be declared with just the class name (without the “public” access modifier).  
  2. All components of this exercise are provided in the instructions above. You will just need to assemble the components as instructed. 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Intelligent Machines
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
  • SEE MORE 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