Thursday, 19 September 2013

Beginner Java trouble with Parameters

Beginner Java trouble with Parameters

I am currently learning Java and have been having problems with parameters
I'm trying to create a program that takes input.. age and classifies the
person based on said age.
< 2 a baby, < 4 a toddler, < 13 a child, < 20 a teenager, < 35 a young
adult, < 65 middle aged, < 100 geriatric, greater than or = 100 antique
It needs to return a string classifying the person, I wrote this
String getMaturityLevel(int age) {
if(age < 2)
maturity = ("a baby");
if(age < 4)
return("a toddler");
if(age < 13)
return("a child");
if(age < 20)
return("a teenager");
if(age < 35)
return("a young adult");
if(age < 65)
return("middle aged");
if(age < 100)
return("geriatric");
if(age >= 100)
return("antique");
}
Which doesn't compile as it needs a return statement, so my problem is,
how do I effectively write the code? I don't know how to store the results
I tried something different with age < 2
Any help would be appreciated.

No comments:

Post a Comment