如何在java中的类数组中输入?

时间:2021-03-06 13:11:42

I am new to java and this is our first assignment but i am unclear right now that why didnt our teacher passes a array of class object to the Add Student method instead he created array of object as private and just passed the name of the array.How can i add data of students now

我是java的新手,这是我们的第一个任务,但我现在还不清楚为什么我们的老师没有将一个类对象数组传递给Add Student方法,而是将对象数组创建为私有,只是传递了数组的名称。我现在如何添加学生数据

  public class StudentManagement {
    private Student students [] ;
    private int CAPACITY ;
    private int CURRENT_POSITION;
    public StudentManagement(){
        CAPACITY = 3;
        CURRENT_POSITION = 0;
        students = new Student[CAPACITY];
    }

    public void addStudent(Student student){


    }

1 个解决方案

#1


1  

As commented by Turing85, Please talk to your instructor to understand the concepts.

如图灵85所评论,请与您的导师联系以了解其概念。

This array can hold 3 objects (CAPACITY).

该数组可以容纳3个对象(CAPACITY)。

CURRENT_POSITION is where you are going to add your object.

CURRENT_POSITION是您要添加对象的位置。

You can try similar to this..

您可以尝试类似于此..

public void addStudent(Student student) {
    if (CURRENT_POSITION < CAPACITY) {
        students[CURRENT_POSITION] = student;
        CURRENT_POSITION++;
    }
}

#1


1  

As commented by Turing85, Please talk to your instructor to understand the concepts.

如图灵85所评论,请与您的导师联系以了解其概念。

This array can hold 3 objects (CAPACITY).

该数组可以容纳3个对象(CAPACITY)。

CURRENT_POSITION is where you are going to add your object.

CURRENT_POSITION是您要添加对象的位置。

You can try similar to this..

您可以尝试类似于此..

public void addStudent(Student student) {
    if (CURRENT_POSITION < CAPACITY) {
        students[CURRENT_POSITION] = student;
        CURRENT_POSITION++;
    }
}