Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago

Question

=+ 4. Why should policymakers think about incentives?

Answered: 1 week ago