I started answering and am posting initially not to miss the long answer, but I realized that the question is in unanswered condition, I will delete if it is not possible to keep. Do not consider this answer as correct yet, I will improve if it is possible to save the question. If you are not very curious or waste time reading yet, I hope soon to be able to leave in the definitive version
When you’re going to train something you’d better take something that makes sense to do. This example does a lot of things that it shouldn’t, probably because it’s just an example, but in software development when it does something meaningless you train to do something meaningless, you get used to it.
The idea of getters and setters is questioned. Not that can not be used, but almost always the use is abused. You can read more here, have a multi-question links.
It’s even more questionable when he gets one array. Incidentally getters and setters is an abstraction and it gets strange to use with such a concrete type in something abstract. It gives the impression that is creating the abstraction without knowing why. Don’t do anything in programming without knowing why you’re doing it. Everything needs to be justified and saying "I’m doing it because everyone else is doing it" is not a good reason. Then you should probably use a list, preferably a list interface. But again, you probably shouldn’t even have all this in the code.
This class organization also seems to make no sense. Classes must exist to solve a problem, must have a purpose, must not be almost random or just because you thought it was nice to put it like that. Even when it comes to naming them if they don’t make a lot of sense it’s already wrong.
In the way this code was written it does not say why it has these classes. If you cannot justify do not do any of this. I’m having trouble rewriting it because I don’t know what this is.
Note that the problem described in the comment has nothing to do with Setter as it is in the question. And I don’t even know if you really understood that one thing has nothing to do with another and that the Setter is not fit for this.
If you’re gonna change the array cannot use the for
of data collection, it serves to take data, but not to assign values in it, access to these elements is read-only, so you need to use the for
Brute who manually sweeps the entire collection. I would make a code if I had understood what combinations are these that you’re trying to make, I didn’t see how to match numerically.
It seems to me that all this should be one class. Maybe I should have one builder, but I’m speculating. It doesn’t seem like you should have Setter, gives the impression that wanted to put one anyway, even without sense, but it can be only because it is not well explained. It seems to me that the getter is a abstraction leak. An idea of code trying to match numbers, but it’s not even this, it looks like it wants to draw numbers, but anyway, it’s something:
public class Program {
public static void main(String[] args) {
Numeros objeto = new Numeros();
objeto.gerador();
for (int item : objeto.getDezenas()) System.out.println(item);
}
}
class Numeros {
private int[] numeros = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
private int[] dezenas = new int[100];
public int[] getDezenas() {
return this.dezenas;
}
public void gerador() {
for (int i = 0; i < numeros.length; i++) {
for (int j = 0; j < numeros.length; j++) dezenas[i * 10 + j] = i * 10 + j;
}
}
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
In this example itself it should not even have all this, it was to be simpler.
The summary of the story: this example unravels. But I even found it useful because we can learn from the error, as long as it is criticizing it constructively.
I do not understand your doubt. I understand what you are trying to do, but not the doubt.
– Maniero
Maniero, in this case is what would be the syntax of a set where will set the value of the memory address in for, like there are dozens[1]. I need to set the value of each array position and I don’t know how to do this using the set
– Weriky Alphazero
The question is still confused about what this is, the comment speaks of something other than the question. I gave you an answer, see if this helps anything in trying to save the question. If it is not possible I will delete the answer and the question will unfortunately have to be closed because it is incomprehensible what is desired.
– Maniero