I have implemented a Mammal
class hierarchy in Java.
Is it an intelligent approach, with respect to decomposition, locality and procedural abstraction?
package Hierarchies;
public class Mammals {
public Mammals(){
}
public void giveMilk(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of produce Milk
System.out.println("Produce milk to feed their babies.");
}
public void haveHair(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Have Hair
System.out.println("Have hair on their bodies.");
}
}
public class Cats extends Mammals{
public Cats(){
}
public void Sounds(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Sound
System.out.println("Meow Meow Meow!!!.");
}
public void Diet(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Diet
System.out.println("Cats are Carnivores.");
}
}
public class Elephants extends Mammals {
public Elephants(){
}
public void Trunk(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Have Trunk
System.out.println("Have Trunk.It functions for grasping, breathing, feeding, dusting, smelling, drinking.");
}
public void Diet(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Diet
System.out.println("Elephants are Herbivorous.");
}
}
public class Dogs extends Mammals {
public Dogs(){
}
public void Bark(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Bark
System.out.println("Woo Woo!!!.");
}
public void Diet(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of Diet
System.out.println("Dogs are Omnivores.");
}
}
public class Sporting extends Dogs {
public Sporting(){
}
public void Race(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of purpose for which they used
System.out.println("Used For Reacing Purposes.");
}
}
public class Working extends Dogs {
public Working(){
}
public void work(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of work they done
System.out.println("Learns and performs tasks to assist and entertain its human companions.");
}
}
public class Pet extends Dogs {
public Pet(){
}
public void Work(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of work they done
System.out.println(" Commonly provide their owners physical and emotional benefits.");
}
}
public class Hunting extends Dogs {
public Hunting(){
}
public void Work(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message for their work
System.out.println(" Hunting dog refers to a canine that hunts with or for humans.");
}
}
public class WolfHound extends Hunting {
public WolfHound(){
}
public void Task(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of task they done
System.out.println(" The breed was originally developed from war hounds to one used for hunting and guarding.");
}
}
public class FoxHound extends Hunting {
public FoxHound(){
}
public void Task(){
//REQUIRES: nothing
//MODIFIES: nothing
//EFFECTS : Display message of task they done
System.out.println(" A foxhound is a type of large hunting hound bred for strong hunting instincts, great energy, and, like all scent hounds, a keen sense of smell.");
}
}
Main Method
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Mammals mam= new Mammals();
Dogs dog= new Dogs();
Cats cat=new Cats();
Elephants elep=new Elephants();
Sporting sport=new Sporting();
Working work= new Working();
Pet pet=new Pet();
Hunting hunt=new Hunting();
WolfHound wolf=new WolfHound();
FoxHound fox =new FoxHound();
System.out.println("Welcome to Mammals Class !!!");
System.out.println("1-Dogs ");
System.out.println("2-Cats ");
System.out.println("3-Elephants ");
System.out.println("Enter the Number To which Mamamal Class You GO ");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.println("1- Sporting ");
System.out.println("2- Working ");
System.out.println("3- Pet ");
System.out.println("4- Hunting ");
int choice2=input.nextInt();
switch(choice2){
case 1:
sport.giveMilk();
sport.haveHair();
sport.Bark();
sport.Diet();
sport.Race();
break;
case 2:
work.giveMilk();
work.haveHair();
work.Bark();
work.Diet();
work.work();
break;
case 3:
pet.giveMilk();
pet.haveHair();
pet.Bark();
pet.Diet();
pet.Work();
break;
case 4:
System.out.println("1- WolfHound ");
System.out.println("2- FoxHound ");
int choice3=input.nextInt();
switch(choice3){
case 1:
wolf.giveMilk();
wolf.haveHair();
wolf.Bark();
wolf.Diet();
wolf.Task();
wolf.Work();
break;
case 2:
fox.giveMilk();
fox.haveHair();
fox.Bark();
fox.Diet();
fox.Work();
fox.Task();
break;
default:
System.out.println("Invalid Choice");
break;
}
break;
default:
System.out.println("Invalid Choice");
break;
}
break;
case 2:
cat.giveMilk();
cat.haveHair();
cat.Diet();
cat.Sounds();
break;
case 3:
elep.giveMilk();
elep.haveHair();
elep.Diet();
elep.Trunk();
break;
default:
System.out.println("Invalid Choice");
break;
}
}
}