Question
Java Programming Assignment: 1- Write an Animal class that has two member variables called weight and height. It should have two member methods called makeNoise
Java Programming Assignment:
1- Write an Animal class that has two member variables called weight and height. It should have two member methods called makeNoise and eat. Both of these methods should only have a print statement saying what that method is. Make the Animals comparable using the weight as the deciding factor of who is bigger. Have setters for both member variables.
2- Write 3 more classes called Dog, Cat and Pig. Each of these classes should have a method called makeNoise. The makeNoise of Dog should have a print statement saying Bark. The makeNoise of Cat should have a print statement saying MEOW. The makeNoist of pig should have a print statement saying OUNK.
3- In main class create two objects of type Cat, two objects of type Dog and two objects of type Pig. Set the height and weight of each one as you like. Create an array of type Animal and save all these 6 objects in this array. Name this array arrayA.
4- Write a for loop in main that repeats 6 times and each time call the method makeNoise by having arrayA[i].makeNoise(). You will see that the same line makes different sounds depending what object is stored in that location of the array. We call this Polymorphism. So you have written a polymorphic code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started