la parte del critical age es esta :
Código:
/**
* this method tell you how many years you have left to be
* 1) adult ,if you are under 18
* 2) retired ,if you are under 67
* 3) you are retired
*/
public String getCriticalAge ()
{
if (age >0 && age <C_ADULT)
return (C_ADULT-age)+" to be adult";
else if ( age <=C_RETIRED && age >=C_ADULT)
return (C_RETIRED-age+" to be retired");
else
return (age-C_RETIRED)+" you are retired" ;
}
y este es el codigo completo
Código:
/**
* Write a description of class person here.
*
* @author roberto fernandez diaz
* @version 20130917
*/
public class person
{
private String name = " Roberto"; // this is the name o f the person
private String surname =" Fernandez Diaz "; //this is your surname
int age =18;//this is your age
private final static int C_RETIRED = 67; //this is the value to be retired
private final static int C_ADULT = 18; //this is the value to be adult
private final static int MIN_AGE_VALUE = 0;
public final static int MAX_AGE_VALUE = 118; //this is the max value for age
public static double height = 1.8; //this is the heihgt of the person.
boolean gender ;
private final static boolean MALE_VALUE = false;
private final static boolean FEMALE_VALUE = true;
public String nationality = "Spain"; //this is the nationality of the person
/**
* Constructor for objects of class person
*/
public person()
{
System.out.println ("person object created");
}
/**
* Constructor for objects of class person
*/
public person(String name, String surname)
{
//System.out.println (setName(name) + setSurname(surname));
System.out.println ("person object created" );
setName(name);
setSurname(surname);
}
/**
* modifies the value for name property
*/
public void setName(String name)
{
this.name = name ;
}
/**
* modifies the value for surname property
*/
public void setSurname(String newSurname)
{
this.surname = surname ;
}
/**
* modifies the value for nationality property
*/
private void setNationality(String nationality)
{
this.nationality = nationality ;
}
/**
* mofies the value for age property
*/
public void setAge(int age)
{ //if age is less than 0 or bigger than 118 show a message to the user
if ( age <MIN_AGE_VALUE || age> MAX_AGE_VALUE)
System.err.print ("age can´t be less than 0 or bigger than 118 ");
else
this.age = age ;
}
/**
* modifies the value for gender property
*/
public void setGender(boolean gender)
{
this.gender = gender ;
}
public void setHeight (double height)
/**
* stablish the height of the people
*/
{
this.height = height;
}
public String toString()
{
if (gender == MALE_VALUE)
return (" NAME: " +name +" AGE: "+ age +" GENDER: MALE" );
else
return (" NAME: " +name +" AGE: "+ age +" GENDER: FEMALE" );
}
/**
* Converts all information contain in this class into a String
*
* @returns String String containing all the data related to this class
*/
public String toStringV2() //la que hay que usar
{
String aux="NAME: "+ getSurname () + name +" AGE: "+ age + " GENDER: ";
if (gender == MALE_VALUE)
aux =aux + "MALE";
else
aux += "FEMALE"; //en lugar de aux + "FEMALE"
return(aux);
}
/**
* returns the value for name property
*/
public String getName ()
{
return name.toUpperCase(); // return it in full uppercase
}
/**
* returns the value for surname property
*/
public String getSurname ()
{
return "DR. " + surname.toUpperCase(); // return it in full uppercase //surname.CONVERT TO UPPERCASE
}
/**
* returns the value for age property
*/
public int getAge ()
{
return age;
}
/**
* this method tell you how many years you have left to be
* 1) adult ,if you are under 18
* 2) retired ,if you are under 67
* 3) you are retired
*/
public String getCriticalAge ()
{
if (age >0 && age <C_ADULT)
return (C_ADULT-age)+" to be adult";
else if ( age <=C_RETIRED && age >=C_ADULT)
return (C_RETIRED-age+" to be retired");
else
return (age-C_RETIRED)+" you are retired" ;
// cambiar string por int y quitar comillas
}
/**
* returns the value for gender property
*/
public boolean getGender ()
{
return gender;
}
/**
* print in the screen a message with features/atributes of people
*/
public void print ()
{
System.out.println (toStringV2() );
}
}