Advertisement
VictorMunoz

VMP_UF4-Reto-Persona

Nov 12th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public class Persona extends Familia{
  2.     // Atributos
  3.     protected String nombre;
  4.     protected int edad;
  5.     protected String dni;
  6.     protected String sexo;
  7.     protected float peso;
  8.     protected float altura;
  9.  
  10.     // Constructor (vacío)
  11.     public Persona() {
  12.         this.nombre= "";
  13.         this.edad= 0;
  14.         this.dni= "";
  15.         this.sexo= "";
  16.         this.peso= 0f;
  17.         this.altura= 0f;
  18.     }
  19.     // Contructor sobrecargado
  20.     public Persona(int numLibFam, String direccion, String poblacion, String provincia, String nombre, int edad, String dni, String sexo, float peso, float altura) {
  21.         super(numLibFam, direccion, poblacion, provincia); // Carga de los atributos de la superclase (Familia)
  22.         this.nombre= nombre;
  23.         this.edad= edad;
  24.         this.dni= dni;
  25.         this.sexo= sexo;
  26.         this.peso= peso;
  27.         this.altura= altura;   
  28.     }
  29.    
  30.     // Getters & Setters
  31.     public String getNombre() { return nombre; }
  32.  
  33.     public void setNombre(String nombre) { this.nombre = nombre; }
  34.  
  35.     public int getEdad() { return edad; }
  36.  
  37.     public void setEdad(int edad) { this.edad = edad; }
  38.  
  39.     public String getDni() { return dni; }
  40.  
  41.     public void setDni(String dni) { this.dni = dni; }
  42.  
  43.     public String getSexo() { return sexo; }
  44.  
  45.     public void setSexo(String sexo) { this.sexo = sexo; }
  46.  
  47.     public float getPeso() { return peso; }
  48.  
  49.     public void setPeso(float peso) { this.peso = peso; }
  50.  
  51.     public float getAltura() { return altura; }
  52.  
  53.     public void setAltura(float altura) { this.altura = altura; }
  54.    
  55.     // Método info
  56.     public String info() {
  57.         return this.nombre +" - "+ this.edad +" - "+ this.dni +" - "+ this.sexo +" - "+ this.peso +" - "+ this.altura +" / "+ infoFamilia();
  58.     }
  59.  
  60.     // Implementación del método abstracto IMC
  61.     @Override
  62.     public float imc(){
  63.         float imc = this.peso/(this.altura*this.altura);
  64.         return imc;
  65.         }
  66.    
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement