info@meritcampus.com    +91-85006-22255
...
`

Write a program using if condition to print whether the person is Man, Boy, Woman or Girl depending upon the gender and age. Note if the age is greater than 25 boy will become man and if the age is greater than 20 girl will become woman.

Input (Integer, Character) Output (String)
`40, 'M'` `Man`
`15, 'M'` `Boy`
`25, 'M'` `Boy`
`35, 'F'` `Woman`
`12, 'F'` `Girl`
`20, 'F'` `Girl`

``` class ClassifyPersonUsingIf {     public static void main(String s[])    {        System.out.println("A person with age 25 and female will be : " + classifyPerson(25, 'F'));    }     public static String classifyPerson(int age, char gender)     {         String result = null; ```
```         return result;     } } ```
Topic:

### User comments below.All of them might not be correct.

From today we are starting an additional contest called, program hint. As part of this we will post a java question. You need to provide a hint about how to solve this program. Two best comments win Rs. 10 and Rs. 7. There is a recharge of Rs. 3 for lucky liker. All the best.

Posted by Merit Campus    2014-11-14 05:59:52

Do not include the code directly, try to explain with out directly using the code.

Posted by Merit Campus    2014-11-14 06:00:22

if(gender=='M')
{
if(age>25)
result="Men";
else
result="Boy";
}
else
{
if(age>20)
result="Woman";
else
result="Girl";
}

Posted by Raju VarshnEy    2014-11-14 06:08:15

Thanks Raju VarshnEy for participating, but as suggested, please do not include the code. We just need the hints which will help the user understand and write the code by himself.

Posted by Merit Campus    2014-11-14 06:15:39

here we have 2 tasks. first we check they are  boy or man and woman or girl based on their ages.so we have to find age as well as gender by usng if else.

Posted by Bahunadam Narendra    2014-11-14 10:38:41

1st case--(first 'if')First check if character(the Second parameter of classifyPerson method) is equal to the character 'M' or not.If it is equal to the character 'M',then check if the age of that male is greater than 25,if it is greater then result="Man",otherwise if age is less than or equal to 25,then the person is a boy,so result="Boy".The second case--(second 'if') is when the second parameter equals 'F'(Which means person is female),if it so,then check the age,if more than 20,then the person is women(So result="Woman" ),otherwise if age is less than or equal to  20 then result="Girl".

Posted by Sudha Snigdha    2014-11-14 11:59:00

here we have 2 inputs from the User the Possible outputs are 4(Man,Woman,Girl,Boy)

here we have 2 possibilites male and female we can decide it using the second parameter

Case 1:
if the given parameter is 'F' we can say output going to be Woman or Girl
we can decide this by using the 1st parameter if the given age is greater than (age>20) than            the output is Woman(Assign result varible with "Woman") if not than out put is Girl(Assign result varible with "Girl")

case 2:
if the Given Parameter is 'M' than we can sat output is either Man or Boy
we can decide this by using the 1st parameter if the given age is greater than (age>25) than          the output is Man(Assign result varible with "Man") if not than out put is Boy(Assign result varible with "Boy")

Posted by Uday Kumar    2014-11-14 12:54:35

Great job guys. We will be including these hints into our site and will be shown to the user when required. These will be really helpful to them. Thank you :-). We will be announcing the results on Monday.

Posted by Merit Campus    2014-11-14 14:52:14

in this program age and genders are user inputs.                                                           if we take checking age as 1st preference then we need to check 4 different conditions 1.age<20,2.age>20,3.age>25,4.age<25 for this we need 4 if conditions.atfer this each if conditions checks gender here we hve 2 possibilities male or female so each if conditions needs one if else condition to find output.                                                                                                                            example take 1st option if age<20 here we know output should be girl or boy so if gender F then output girl else boy.similarly for other conditions.                                              this type of checking needs 4 if conditions and 4 if else conditions.                                             if we take gender checking 1st preference then we need to check 2 differnt conditions 1.gender=='M',2.gender=='F',after checking this each if conditions checks age depends on gender .                                                                              example gender=='M' thn it is enough to check age>25 and age<25.                              so here 2 if conditions 2 ifelse conditions used.                                                                             for checking this gender 1st preference we can use following option also:                                        just use 1 if else condition for checking any one of the gender .                                       example if part checks 'M' then else part should chck 'F',thn inside if part give one if else to chck age >25 or <25.                                                                                else part if else condition chck age >20 or <20.                                                       by using this type we can eliminate many conditions,it needs only 3 if else conditions.                                                                                                                              so we need to select 1st checking preference to input which hs less possibilities of checking.in this program gender 2 possibilities age 4 checking possibilities.so 1st find gender then find boy,gir,woman,man from age

Posted by Maheshwari Natarajan    2014-11-16 03:51:17

This dose is now closed and the winners are Sudha Snigdha,  for 'First Correct Comment', Uday Kumar,  for 'Second Correct Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-11-17 09:46:14