使用用户输入创建对象以存储在 Java 数组中

Creating object using user input to store in Java array

我的作业如下:

"创建一个程序来跟踪学生的特定信息。存储的信息应如下所示: 名字、姓氏、专业、GPA、UIN、NetID、年龄、性别、 对于这个简单的程序,我们只需要将 10 个学生存储在一个数组中。您的学生应该存储在一个名为 Student 的对象中。 您应该能够在数组中添加、显示和删除学生。 您将提交 2 个文件进行评分:Lab3Driver.java 和 Student.java"

我目前对如何使用用户输入创建具有所有单独属性的学生对象感到困惑。

到目前为止我的代码:

 public class StudentData{
            public static void main(String[] args){ 
                //Creating an info class for the student object
                StudentData studentA = new StudentData((strFirstName, strLastName, strMajor, 
                intGPA, intUIN, strNetID, intAge, strGender));​

                String strFirstName;
                String strLastName; 
                String strMajor;
                int intGPA;
                int intUIN;
                String strNetID;
                String strAge;
                String strGender;

                StudentData(){
                    // Capturing user input into class attributes
                    Scanner input = new Scanner(System.in);
                    System.out.println("Enter First Name");
                    strFirstName = input.nextLine();

                    System.out.println("Enter Last Name");
                    strLastName = input.nextLine();

                    System.out.println("Enter Major");
                    strMajor = input.nextLine();

                    System.out.println("Enter GPA");
                    intGPA = input.nextLine();

                    System.out.println("UIN");
                    intUIN = input.nextLine();

                    System.out.println("Enter netID");
                    strNetID = input.nextLine();

                    System.out.println("Enter Age");
                    strAge = input.nextLine();

                    System.out.println("Enter Gender");
                    strGender = input.nextLine();
                }

创建一个 class student,每个字段都有变量:

public class Student {
    public String strFirstName;
    public String strLastName; 
    public String strMajor;
    public int intGPA;
    public int intUIN;
    public String strNetID;
    public String strAge;
    public String strGender;

    public static void Student(String strFirstName, String strLastName, String strMajor, int intGPA, int intUIN, String strNetID, String strAge, String strGender) {
        this.strFirstName = strFirstName;
        this.strLastName = strLastName;
        this.strMajor = strMajor;
        this.intGPA = intGPA;
        this.intUIN = intUIN;
        this.strNetID = strNetID;
        this.strAge = strAge;
        this.strGender = strGender;
    }
}

创建学生:

Student mystudent = new Student(firstname, lastname, major, GPA, UIN, netID, age, gender);

创建学生数组:

Student[] myarray = new Student[length];

正在将学生添加到数组中:

myarray[0] = new Student(firstname, lastname, major, GPA, UIN, netID, age, gender);