Question
Design a Java class for Person with the following behaviours: talk, in which a person can talk a sentence, if s/he is at least two-year
Design a Java class for Person with the following behaviours:
talk, in which a person can talk a sentence, if s/he is at least two-year old.
eat, in which a person can eat something if s/he is hungry. If the person eats something, then s/he becomes full (not hungry).
needFood, in which the persons status will become hungry if s/he is currently full.
walk, in which a person will walk a specific distance. If a person walks more than four kilometers, then s/he becomes tired and is not able to walk anymore.
sleep, in which a person will sleep if s/he is awake. If a person sleeps, then s/he is no tired anymore, her/him walking distance will reset, and s/he can walk again. Note that if a person is sleeping, s/he cant walk.
awake, in which the person is awaken if s/he is currently sleeping.
grow, in which the persons age will increase by one year. If a person reaches to 55, then his ability to walk will decrease by half every five years.
You need to indicate all the instance variables (properties) a give person should have to be able to handle the above list of behaviours, and store the current states of a given person. For instance, every person has name, age, current distance of walking, sleeping status, walking distance capability, etc. After designing the Person class, implement it as a Java class. Then write a tester Java program to test that class by creating some Person instance objects and do some actions for each of them. To make sure that your tester program tests all the functionalities of a given person, you have to call every method of the class at least once.
Bonus (3 points): Assume that every person can have one friend, which is another person. Therefore, two other behaviors for a person could be getFriend and changeFriend. Modify the Person class that you have designed to be able to handle these two behaviours as well. Note that you need to have another instance variable as well.
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