88.9%

Ok usually I wouldn't mind losing a few points or so on an assignment but when I am a little more than 1% away from an A I am obligated to ask for help. So far I have completed 3/4 of my assignment but need to create one(1) last class to fully finish: the problem is stated below-
Problem: Write a test driver class that creates an array of type Animal. Instantiate Hippo, Lion, and Tiger objects in the array. Use a for loop(in the driver class) to cycle through the animals and their various behaviors.
I WOULD APPRECIATE ANY HELP!
THANK YOU
The code I have so far is below
public abstract class Animal
     protected String name;
     protected int age;
     public Animal(String n, int a)
          name = n;
          age = a;
     }//Animal method
     public String getName(){return name;}
     public int getAge() {return age;}
     public void makeNoise()
          System.out.println("Generic animal noise");
     }//method makeNoise
     public abstract void eat();
     public abstract void sleep(int minutes);
     public void roam()
          System.out.println("Generic Animal roam");
     }//roam method
}//Animal classHippo Class
public class Hippo extends Animal
     private int bodyMass;
     public Hippo(String n, int a, int bm)
          super (n,a);
          bodyMass=bm;
     }//Hippo method
     public void eat()
          System.out.println(name + " is eating.");
     }//eat method
     public void sleep(int m)
          System.out.println(name + " is sleeping for "+m+" minutes.");
     }//sleep method
}//Hippo extends Animal classHippo Test Driver
public class HippoTest
     public static void main(String[] args)
          Hippo hippo=new Hippo("Big Boy", 4, 1250);
          hippo.eat();
          hippo.roam();
          hippo.makeNoise();
          hippo.sleep(22);
     }//main method
}//HippoTest classFeline Abstract Class extends Animal
public abstract class Feline extends Animal
     public Feline (String n, int a)
          super (n,a);
     }//feline class
     public void roam()
          System.out.println(name + " is roaming through the grass.");
     }//roam method
}//Feline classLion Class
public class Lion extends Feline
     public Lion(String n, int a)
          super(n,a);
     }//Lion method
     public void eat()
          System.out.println(name + " is eating fish.");
     }//eat method
     public void sleep(int m)
          System.out.println(name + " is taking a nap for " + m +  " minutes.");
     }//sleep method
}//Lion extends Feline classLion Test Driver
public class LionTest
     public static void main(String[] args)
     Lion lion=new Lion("Mufasa", 19);
     lion.eat();
     lion.roam();
     lion.makeNoise();
     lion.sleep(60);
     }//main method
}//LionTest classTiger Class
public class Tiger extends Feline
     public Tiger(String n, int a)
          super(n,a);
     }//Tiger method
     public void eat()
          System.out.println(name + " is eating English homework.");
     public void sleep(int m)
          System.out.println(name + " is sleeping for " + m + " minutes.");
}//Tiger extends Feline classTiger Test Driver
public class TigerTest
     public static void main(String[] args)
     Tiger tiger=new Tiger("Tigger", 12);
     tiger.eat();
     tiger.sleep(300);
     tiger.roam();
     }//main method
}//TigerTest class

denxnis wrote:
Write a test driver class that creates an array of type Animal. Instantiate Hippo, Lion, and Tiger objects in the array. Use a for loop(in the driver class) to cycle through the animals and their various behaviors.According to your problem, you need a "test driver class" which contains an array of type Animal. The problem is simple enough to do. You have some test driver classes already, and they do not seem to use an array.
According to the description of the problem, you need something that would do the following:
- Declare an array of animals, initialize it to hold three Animal objects
- Instantiate the Hippo, Lion, and Tiger classes and store them in the array
- Use a for (or for-each) loop to call the various methods of each animal
denxnis wrote:
Can someone create a test Driver --- We are not here to do your homework/assignments for you, but if there is something that you do not understand, we can help with that (if you give enough information).

Similar Messages

Maybe you are looking for