Hello, I have a Student class with the name and license plate attributes. The user can enter the name by the setNome (), but I would like to know how to make the registration automatically generated (1, 2, 3, ...)
Hello, I have a Student class with the name and license plate attributes. The user can enter the name by the setNome (), but I would like to know how to make the registration automatically generated (1, 2, 3, ...)
Create a class that will have the value static
and will always return the value with increment, eg:
public class GeradorMatricula {
private static int ID = 1;
public static int getProximaMatricula() {
return ID++;
}
}
public static void main(String[] argv) {
System.out.println(GeradorMatricula.getProximaMatricula());
System.out.println(GeradorMatricula.getProximaMatricula());
}
1
2