Call a FULL ARRANGEMENT of a class in a different class and use it in a FOR and IF cycle?

0

How can I send an array with values to another class, go through it (with a for) and validate each index (with an if) to send a message if it is complete or send an error message. It is a method in the class Validations that resiva the object of the main Maybe they are simple or trivial things but I am new in this. I leave my code:

public static void main(String[] args) 
    {
//AQUI INSTANCIE UN OBJETO DE LA CLASE BANDA 
Banda arreglo = new Banda();
Musico[] musico = arreglo.musico;

Instrumento guitarra = new Instrumento("guitarra","cuerdas");
Musico AngusYoung = new Musico("AngusYoung","solista",guitarra);
AngusYoung.setInstrumento(guitarra);

Instrumento voz = new Instrumento("voz","viento");
Musico BrianJohnson = new Musico("BrianJohnson","vocalista",voz);
BrianJohnson.setInstrumento(voz);

Instrumento guitarraritmica = new Instrumento("guitarra ritmica","cuerdas");
Musico MalcolmYoung = new Musico("MalcolmYoung","ritmico",guitarraritmica);
MalcolmYoung.setInstrumento(guitarraritmica);

Instrumento bajo = new Instrumento("bajo","cuerdas");
Musico CliffWilliams = new Musico("CliffWilliams","bajista",bajo);
CliffWilliams.setInstrumento(bajo);

Instrumento bateria = new Instrumento("bateria","percusion");
Musico ChrisSlade = new Musico("ChrisSlade","baterista",bateria); ChrisSlade.setInstrumento(bateria);

musico[0]= AngusYoung;
musico[1]= BrianJohnson;
musico[2]= MalcolmYoung;
musico[3]= CliffWilliams;
musico[4]= ChrisSlade;
}

    public class Banda {

    Musico musico[] = new Musico[5]; //ARREGLO


    public Banda() {


    }

    public Musico[] getMusico() {
        return musico;
    }

    public void setMusico(Musico[] musico) {
        this.musico = musico;
    }


    public String toString() {
        return "Banda{" + "musico=" + musico + '}';
    }

    public class Validaciones {  //EN ESTA CLASE DEBO MANDAR A LLAMAR EL ARREGLO QUE SE LLENO EN EL MAIN

    //SUPUESTO METODO QUE RESIVE EL ARREGLO LLENO DEL MAIN
    public Musico band (Musico[] musico){

        //CREO QUE SE DEBE ASIGNAR A UNA VARIABLE PARA USARLO 

        //AQUI DEBERIA ESTAR EL IF Y EL FOR 

        return null;

    }

}

I have researched but it is not clear to me how to handle an array as an object in a method.

    
asked by Erick 03.08.2018 в 05:29
source

1 answer

-1

What you are doing is fine.

To call the method of the Validations class, you only need to install an object of the same

Validaciones v = new Validaciones ();

And then to call the method you just have to do

v.band(musico);

The problem with your code is that your class Band does not really have any music, because you did not assign the musicians to the array within that class, but you assigned them to an array of the main.

What's more, with the band class, you did not do anything, you just instanced it.

Going through the arrangement can be done with a for or a foreach, and that is your exercise;)

    
answered by 03.08.2018 / 05:44
source