subject

Animals need energy to move. They get energy from eating food while moving consumes energy. Create a class Animal with a constructor that takes no parameters and has an instance variable: private int energy;
When an animal is "born," it has one unit of energy. It has the methods
public void eat(int amountToEat) - which increases the amount of energy the animal has by amountToEat
public void move(int amountToMove) - which decreases the energy the animal has by amountToMove.
public int getEnergy() - which returns the amount of energy left
Notice there is no setEnergy method. Energy is only changed by eating or moving.
Since it isn't realistic for animals to be able to gather infinite amounts of energy, to have negative energy or to eat or move a negative amount, you should create a subclass BetterAnimal which has a cap on the amount of energy an animal can have.
The constructor takes a parameter that specifies a maximum for energy. You will need to save this in another instance variable.
Override the eat and move methods
In the eat method: If the amount the BetterAnimal eats would set its energy above the max, the energy level is only increased to the max. Also energy is only changed if the amount > 0
In the move method: Energy changes only if amount > 0. The energy can never be less than 0. If an BetterAnimal has an energy of 2 and tries to move 5, its energy will be 0.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 07:30
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits.now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order.finally, output thedigits in thearray.use at least two functions to organize your program.
Answers: 3
question
Computers and Technology, 23.06.2019 20:40
On nba 2k 19, every time i try to join a my park game, it leads ro a website telling my dad that he needs ps plus. i already have ps plus though. how do i fix this?
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
question
Computers and Technology, 24.06.2019 13:30
Which of the following is not a “fatal four” event?
Answers: 2
You know the right answer?
Animals need energy to move. They get energy from eating food while moving consumes energy. Create a...
Questions
question
Mathematics, 26.10.2020 20:20
question
English, 26.10.2020 20:20
Questions on the website: 13722361