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. ear, in which a person can eat something if s/he is hungry. If the person cats something, then she becomes full (not hungry). needFood, in which the person's status will become hungry if she is currently full walk, in which a person will walk a specific distance. If a person walks more than four kilometers, then she 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 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 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 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 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. 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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

software development products, processes, and resources

Answered: 1 week ago

Question

=+Discuss the importance of research in social media practices

Answered: 1 week ago