No puedo aumentar el valor studentID en Para

Jon Andrew:

Estoy haciendo algo de código en Java, pero no funciona:

java.util.Scanner importación;

java.util.Arrays de importación;

public class Principal {

    public static void main(String[] args) 
    {
        Scanner input = new Scanner(System.in);

        String [] studentId = new String [3];

        Student name;

        for (int i = 0; i < 3; i++) 
        {
        System.out.print("Enter Name => ");
        name = new Student(input.next());
        studentId[i] = name.toString();
        }
        for (int i = 0; i < 3; i++) 
        {
        System.out.println(studentId[i]);
        }    
}
}
public class Student
{
    private static int studentId;
    private String name;

    public Student(String name) 
    {
    this.name=name;    
    setStudentId(studentId++);
    }

    public int getStudentId() 
    {
    return studentId;
    }

    public void setStudentId(int studentId) 
    {
    this.studentId = studentId;
    }

    @Override
    public String toString()
    {
        return (this.studentId +" "+ "student is "+ " " + "(" + this.studentId + ")"+ this.name);
    }
}

Necesito incremento automático de la identificación cuando se crea una nueva entrada. Intento todo, pero aún no puedo aumenté.

PhuLuong:

En el constructor que debe ser:

{
    public Student(String name) 
    {
        this.name=name;    
        setStudentId(studentId + 1);
    }
}

Supongo que te gusta

Origin http://10.200.1.11:23101/article/api/json?id=404514&siteId=1
Recomendado
Clasificación