elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Informática
| |-+  Software
| | |-+  problema al testear con blueJ , con rangos
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema al testear con blueJ , con rangos  (Leído 1,153 veces)
robertofd1995

Desconectado Desconectado

Mensajes: 172


Ver Perfil
problema al testear con blueJ , con rangos
« en: 13 Octubre 2013, 15:13 pm »

hola a todos , veran estoy en el primer año de carrera de informatica y el otro dia empezamos a hacer un test del programa con blueJ, con los metodos normales de mi programa , como fijar edad , nombre , genero , etc.. no tengo problema , el problema se me presenta cuando tengo que hacer el test de un metodo llamado crticalAge, que lo que hace es en funcion de los años que tengas , te dice si eres adulto , joven o retirado y los años que te quedan para la siguiente etapa , como hago para testear con esos rangos , os dejo aqui el codigo

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() );
        
    }
    
    
    
}




« Última modificación: 13 Octubre 2013, 15:41 pm por robertofd1995 » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
sistema de rangos « 1 2 »
Sugerencias y dudas sobre el Foro
NiCoLaS HdL 10 5,418 Último mensaje 5 Enero 2006, 18:03 pm
por JuszR
existe bluej en versión de c++?
Programación C/C++
flacc 0 2,016 Último mensaje 14 Abril 2012, 08:43 am
por flacc
Ayuda con objeto en BlueJ
Java
Fischer987 2 2,741 Último mensaje 12 Junio 2012, 00:28 am
por Fischer987
problema al intentar clasificar a las personas con genero , blueJ
Programación General
robertofd1995 5 5,306 Último mensaje 17 Septiembre 2013, 18:17 pm
por DarK_FirefoX
[Problema Reto C/C++] Sumatoria de Rangos de Impares
Programación C/C++
AlbertoBSD 5 2,311 Último mensaje 14 Marzo 2017, 17:16 pm
por AlbertoBSD
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines