jueves, 17 de agosto de 2017

perro con objetos y sus movimientos

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author SEDUCA
 */
public class Perro {
 //atributos:
    private String nombre;
    private String raza;
    private int nivelHambre;
   
    //constructor vacio
    public Perro( ){
   
       
    }
    //constructor sobre cargado
    public Perro(String Nombre, String Raza, int nivelHambre){
        this.nombre=nombre;
        this.raza=raza;
        this.nivelHambre=nivelHambre;
    }
    //setters: //recibe unargumento y lo envia a un elemento que es this.nombre
    public void setNombre(String nombre){
        this.nombre=nombre;
    }
    public void setRaza(String raza){
        this.raza=raza;
    }
       
    public void setNivelHambre(int nivelHambre){
        this.nivelHambre=nivelHambre;
    }
   
   
    //Getters:
    public String getNombre(){
        return this.nombre;
   
    }
   
    public String getRaza(){
        return this.raza;
   
    }
   
    public int getnivelHambre(){
        return this.nivelHambre;
   
    }
   
    //sobre escritura del metodo "toString()"
  // @Override
    //public String toString(){
   
   //return "Esto es un perro -->>"+this.nombre+" "+
   ///       this.raza+" "+
      //   this.nivelHambre;
   
   
    //}
    //*************************
    public void alimentar(int porciones){
        if(this.nivelHambre==10){
            System.out.println("El perro esta lleno no se le puede alimentar");
        }else{
        if((this.nivelHambre+porciones)==10){
            System.out.println("ya se lleno");
            this.nivelHambre=this.nivelHambre+porciones;
           
        }else{
            if((this.nivelHambre+porciones)<10){
               
                System.out.println("todavia puede comer un poco mas");  
                this.nivelHambre=this.nivelHambre+porciones;
                      
            }else{
               
                System.out.println("se lleno y sobraron"+
                        (this.nivelHambre+porciones-10)+" porciones ");
                        this.nivelHambre= 10;
            }
        }
   
   
}}
}

No hay comentarios:

Publicar un comentario

Los mail de oulook no se pueden reenviar.

 cuando en el asunto poseen un caracter especial por ejemplo @#$ los correos no salen y no te muestra ningun correo de rebote, especialmente...