Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

10. What steps can providers take to control variation?

Answered: 1 week ago

Question

2. Do the same for your favorite female film character.

Answered: 1 week ago