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, 22.06.2019 07:30
Jasper and samantha are in a robotics competition. the guidelines state that the robots should be able to move a 10-gram weight at least 2 meters and turn in a circle. jasper and samantha have already built the robot. which step of the design process should they follow next to decide whether their robot meets the minimum criteria for the competition?
Answers: 1
question
Computers and Technology, 22.06.2019 10:00
Jackson is teaching the decimal number system. he wants his students to know how to expand numbers by powers of 10. which is the correct order in which digits are assigned values in the decimal number system?
Answers: 1
question
Computers and Technology, 22.06.2019 17:30
Type the correct answer in the box. spell all words correctly. under which key category do the page up and page down keys fall? page up and page down keys fall under the keys category.
Answers: 3
question
Computers and Technology, 23.06.2019 13:00
In excel - calculate the actual increase/decrease from first quarter to the second quarter then subtract subtract first quarter value from second quarter total then divide result by first quarter value
Answers: 1
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, 25.06.2019 04:30
Questions on the website: 13722363