I´m having problems with this part of the code, but I´m not sure why. I´m struggling to understand objects, I cant find the error here.
The butacas 2D matrix is created in main.
CodePudding user response:
Maybe because of language differences I don't get the problem right I discuss what I've found out.
You had some kind of seats and viewers/spectators. The seats are placed in rows and columns like a 2D array. You have to iterate over this array and you have problems with it.
Speaking about arrays in java, they don't have length()
method but length
field, which can be accessed like myArray.length
. You can further read about arrays here.
In your code you have defined butacas as some kind of Espectador
object. It looks like Espectador
doesn't have the method getLength()
and neither can be used like an array with the brackets. (For example: myArray[index]
) If butacas is some other kind of object, then I cannot tell which method does it have for its length.
If butacas is a 2D array, your method should look like this:
static void asignarButacaEspectador(String espectador, Espectador[][] butacas) {
for (int i = 0; i < butacas.length; i ) {
for (int j = 0; j < butacas[i].length; j ) {
}
}
}
Also please note, that we usually start the variable/parameter names with lowercase letters in java. You can find some basic naming conventions at Oracle's site.
If you have a different data structure for butacas please share it with me.
CodePudding user response:
I needed to only use espectador as an attribute and butacas was in the class already therefore I deleted the butacas attribute and ended up with this: [1]: https://i.stack.imgur.com/e3ab4.png