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 01:40
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
question
Computers and Technology, 23.06.2019 16:30
Monica and her team have implemented is successfully in an organization. what factor leads to successful is implementation? good between different departments in an organization leads to successful is implementation.
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
1. for which of the following are you not required to signal beforehand? a. changing lanes b. speeding up c. stopping
Answers: 2
question
Computers and Technology, 24.06.2019 03:30
Auniform resource locator (url) is a formatted string of text that web browsers, email applications, and other software programs use to identify a particular resource on the internet. true false
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, 14.10.2020 01:01
question
English, 14.10.2020 01:01
question
English, 14.10.2020 01:01
question
Mathematics, 14.10.2020 01:01
question
Arts, 14.10.2020 01:01
question
Mathematics, 14.10.2020 01:01
Questions on the website: 13722363