edit/ My mistake, I wanted it to be the simplest to explain and understand, but it ended up being counterproductive, my apologies and thank you very much for your advice, Mr. Benito.
well, my current situation is two problems, the first is that I want to create multiple instances of the grasshopper class according to the time that the variable time_reproduction stipulates, but I want that when creating the name of said instance it has a number that changes, for example "grasshopper grasshopper1 = new grasshopper... and that said 1 is changed by a 2, 3, etc, the problem is that I want that number to be given to me by a variable, that's why I have variables like hello and chain, since I was doing tests, but it didn't work for me.
My second problem that is related to this is that I want to use the getcant_grasshopper method as the numeric variable in the Playback class, and the only way is to set the cant_grasshopper variable to static, but this modifies even the et and set and I don't know if it's the most suitable way, I hope I have explained myself well, any suggestion, help or something that I am doing wrong is appreciated.
package proyectoprogra;
import java.util.Random;
public class Reproduccion {
private int min_reproduccion;
private int max_reproduccion;
protected int tiempo_reproduccion;
protected int reloj_reproduccion;
protected int segundos;
public int hola = 5;
public String cadena;
public void reproduccion(){
cadena = Integer.toString(hola);
Random rand = new Random(System.currentTimeMillis());
tiempo_reproduccion = rand.nextInt(max_reproduccion-min_reproduccion)+min_reproduccion;
for(segundos = 0; segundos<tiempo_reproduccion;segundos++){
delaysegundo();
}
if(segundos == tiempo_reproduccion){
Saltamontes saltamonte = new Saltamontes("juan");
saltamonte.getNombre();
}
}
private static void delaysegundo(){
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
}
}
I leave attached the Grasshopper class in case it helps to understand.
package proyectoprogra;
public class Saltamontes {
private String nombre;
private int cant_saltamontes;
//CONSTRUCTOR
public Saltamontes(String nombre) {
this.nombre = nombre;
}
//GETTERS y SETTERS
public int getCant_saltamontes() {
return cant_saltamontes;
}
//GETTERS AND SETTERS
public void setCant_saltamontes(int cant_saltamontes) {
this.cant_saltamontes = cant_saltamontes;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
Regarding the second question:
yes, you need a static variable initialized to 0 or 1. You can create a getter without major problems and create a setter too but, any of the instances can modify the value of the static variable (is it necessary??).
}
test in main
* instance getter and setter can be created by removing the static or creating others with different names
Regarding the first part of the question, it is not clear to me what you want to do, but creating variable names (or new variables) at runtime is not recommended (* I don't know if it is possible in java, someone correct me if I'm wrong*), use a data structure that allows you to store a variable number of instances such as an arrayList or another more convenient for your application.