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
-
Discoverer report returns no data from a certain time
Using Discoverer 10g,a discoverer report which returned data normally last month gets to return no data now. We have four same environments, and two of them has this problem, two is OK. And the SQL of the discoverer of the four environments are the s
-
In LR 5. Recently I noticed my processed images are sharper in the Library mode than in the Develop mode. This makes doing adjustments difficult because I can't really tell the effect of the adjustments. PC, i7, 24GB RAM. I've tried purging the Camer
-
How use Active X object in sap 2005A SP14
How use Active X object in sap 2005A SP14 with usercontrol in vb.net or control in vb.net please show example code Thanks for advance
-
Transfer Photoshop 5.0 Elements to another computer
How do I transfer my Photoshop Elements 5.0 to another home computer?
-
FacesContext can't display error msg !
Hi guys, I got this problem. For this function: public User saveUser(User user) throws DBException { try { User newUser = this.userDao.saveUser(user); return newUser; } catch (DataIntegrityViolat