Question: Write a Java program that stores the information of a person ( Person class) and then it calculates the number of calories this person's body

Write a Java program that stores the information of a person (Person class) and then it calculates the number of calories this person's body needs. The class should include the following variables:

The person's name (sName): String

The person's age (age): int

The person's weight (weight): double

The person's length in cm (length): double

The person's gender (gender): String

Use the following guidelines:

Create the Person class above with all variables private except the variable (gender) should be public. Add a constructor with parameter. Add setters and getters for all private variables.

In the client class (TestPerson class), add a function call it calCalories and allow it to receive an object from the Person class. You can calculate the calculate as following:

If the person was (male) ,then calories= 6.25*length +10*weight - age*5 +5

If the person was (female),then calories= 6.25*length +10*weight age*5 -161

Then allow your function to return the calculated calories.

In the client class, create an array of objects (name it p1) of this class with the values

sName= Mohamed, age=20, weight=55, length=160, and gender=male.

sName= Mahmoud, age=25, weight=80, length=170, and gender=male.

sName= Fahd, age=30, weight=60, length=166, and gender=male.

sName= Amal, age=30, weight=60, length=166, and gender=female.

Pass this object to the calCalories function and print the calculated calories for each person and his/her age from the main method.

Sample Run:

The required calories for a 20 years male is :1455.0

The required calories for a 25 years male is :1742.5

The required calories for a 30 years male is :1492.5

The required calories for a 30 years female is :1326.5

In the client class (TestPerson class), add a function call it MatchStartedbyChar that uses regular expression to print the names of persons started with a specific character.

In the client class (TestPerson class), add also another function call it MatchEndbyChar that uses regular expression to print the names of persons ended by a specific character.

Test the two methods by passing character M and then character A to MatchStartedbyChar and passing character d to MatchEndbyChar method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!