Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 6. (25 points) Goal: Practice how to create user-defined classes in Java. Design a Java class for Person with the following behaviours: talk, in

image text in transcribed

Problem 6. (25 points) Goal: Practice how to create user-defined classes in Java. 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 i s/he is hungry. If the person eats something, then s/he becomes full (not hungry). needFood, in which the person's 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 slccp if s/he is awake. If a person slccps, then s/he is no tired anymore, her/him walking distance will resct, and s/hc can walk again. Note that if a person is slccping, s/hc can't walk. awake, in which the person is awaken if s/he is currently sleeping. grow, in which the person's age will increase by one year. If a person reaches to 55, then his ability to walk will decrease by hall every five years. You need to indicato all the instance variables (propertics) a givc person should have to be able to handle the above list of behaviors 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. Assume that every person can have onc friend, which is another person. Therefore, two other behaviors for a person could be getFriend and changeFriend. Modify thc 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. Java file names: Person.java and TestPerson.java

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions