How do I transfer data from the inherited array(Objects) to the array(reserves)?

Asked

Viewed 26 times

0

package pkg2017ppfp09;

import ObjectManagement.ContainerOfObjects;


/**
*
* @author pf
*/
public class GestorDeReservas extends ContainerOfObjects{
private final int MAX_RESERVAS = 10;
private final Reserva[] Hist = new Reserva[10];
private Reserva[] reserva;

public GestorDeReservas(Reserva[] reserva) {
    super(reserva);
    this.reserva = new Reserva[MAX_RESERVAS];
}  

public GestorDeReservas(Reserva[] reserva,int maxsize) {
    super(reserva);
    this.reserva = new Reserva[maxsize];
}  

public boolean addObject(Reserva reserva) {
    boolean i=false;
    i=Verificar_reservas((Reserva) reserva);
    if(i==true){
        super.addObject(reserva); 
        //transferObj();
        return true;       
    }else{
         return false; //To change body of generated methods, choose Tools | Templates.
    }
}    

private Reserva[] transferObj(){     
        return (Reserva[])getAllObj();
}








private boolean Verificar_reservas(Reserva reserva){
   Reserva temp = new Reserva();

   temp = reserva;
   for (Reserva reserva1 : this.reserva) {
       if (reserva1 != null && reserva1.getAnimal().equals(temp.getAnimal()) && reserva1.getData().equals(temp.getData())) {
           return false;
       }
   }
   return true;
}

public boolean concluida(Reserva reserva){
    Reserva temp = new Reserva();
    temp = reserva;
    for (Reserva reserva1 : this.reserva) {
        if (reserva1.getAnimal().equals(temp.getAnimal()) && reserva1.getData().equals(temp.getData())) {
            reserva1.setConluida(true);
            return true;
        } 
    }
    return false;
}

public boolean Hist(Reserva[] hist){
    for(int i=0;i<this.reserva.length;i++){
       if(this.reserva[i].getConluida()==true){
           hist[i]= this.reserva[i];
       }
    }
    return true;
}

public void listNconcl(DATA data){ 

    for (Reserva reserva1 : this.reserva) {
        if (reserva1.getData() == data) {
            System.out.println(reserva1.getAnimal().getANIMAL_NOME());
        }
    }   
}

}

inserir a descrição da imagem aqui

I wonder how to pass the array if possible in inherited to the reserves.

  • What is inherited?

  • The inherited is basically the "Object" that comes from the superclass. But I have found a solution to my problem.

1 answer

0


To solve the problems I simply created two new methods one in the superclass to fetch an Object and the other to match that Object to this.reserva[i].

Method created in the superclass to fetch an Object:

protected Object getObject(Object obj){
    Object temp = new Object[this.objects.length+1];
    for (Object object : this.objects) {
        if (obj.equals(object)) {
            temp = object;  
        }
    }
    return (Object) temp;
}

Method to match the Object I went to get inherited to this.reserva[i]:

private void tranfer(Reserva reserva){
    for(int i=0;i<this.reserva.length+1;i++){
        if(this.reserva[i]==null ){
            this.reserva[i]=(Reserva) super.getObject(reserva);
            i = this.reserva.length+10;
        }
    }    
}

Upshot:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.