在java.util中获取Error ArrayList不接受参数

时间:2016-10-10 12:28:38

标签: java arraylist

我做了一个班级"学生"现在我试图将我的Student对象存储在ArrayList中,但是在编译ArrayList不接受accept参数时我收到错误。我已多次检查我的代码,但无法找到问题。

Error Picture

我的学生班是这个

public class Student
{
//declaring variables 
private int rollNumber ;
private String name ;


//a counter for counting how many students or objects are declaired yet
public static int studentCount = 0;
public static int getStudentCount()
{
    return studentCount;
}


//getters for both variables
public int getRollNumber()
{
    return rollNumber;
}
public String getName()
{
    return name;
}


//setters for both variables 
public void setRollNumber(int x)
{
    if (x > 0)
    {
        this.rollNumber = x;
    }
    else
    {
        System.out.println("Wrong Roll Number Value");
    }
}
public void setName(String someName)
{
    this.name = someName;
}


//default constructor
public Student()
{
    setName("Please Enter A Name");
    this.rollNumber = 0;
    studentCount +=1;
}


//parameterized constructor
public Student(String name, int x)
{
    setName(name);
    setRollNumber(x);
    studentCount += 1;
}


//copy constructor
public Student(Student s)
{
    setName(s.name);
    setRollNumber(s.rollNumber);
    studentCount +=1;
}

//defining an print method 
public void print()
{
    System.out.println("Student Name = " + name + "______Roll Number = " + rollNumber);
}
}

以及我推荐它的课程如下

import java.util.*;

public class ArrayList
{
    public static void main (String[] anyString)
{
    //Creating Some student objects
    Student s1 = new Student("Ammar" , 1);
    Student s2 = new Student("Ahmad" , 2);
    Student s3 = new Student("Arslan", 3);


    //Creating an arraylist
    ArrayList<Student> someList= new ArrayList<Student>();


    //checking if our Array List is empty or not 
    boolean empty = someList.isEmpty();
    if (empty == true)
        System.out.println("ArrayList is Empty \n\n");


    //adding our student class objects to our arraylist
    someList.add(s1);
    someList.add(s2);
    someList.add(s3);


    //checking if arraylist is empty or not 
    empty = someList.isEmpty();
    if (empty == true)
        System.out.println("ArrayList is Empty");
    else
    //counting total members in a list 
    System.out.println("Our ArrayList someList have a total of " +someList.size() + " Members \n\n");


    //geting back objects from arraylist or extractin them from list 
    //we will display our objects to console one by one 
    for (int i = 0; i < someList.size() ; i++)
    {
        Student one = someList.get(i);
        one.print();
    }
}
}

1 个答案:

答案 0 :(得分:2)

清理并重命名。

[Pipeline] parallel
[Pipeline] [aaa] { (Branch: aaa)
[Pipeline] [bbb] { (Branch: bbb)
[Pipeline] [ccc] { (Branch: ccc)
[Pipeline] [ddd] { (Branch: ddd)
[Pipeline] [eee] { (Branch: eee)
[Pipeline] [aaa] echo
[aaa] build_if_needed: eee
[Pipeline] [aaa] }
[Pipeline] [bbb] echo
[bbb] build_if_needed: eee
[Pipeline] [bbb] }
[Pipeline] [ccc] echo
[ccc] build_if_needed: eee
[Pipeline] [ccc] }
[Pipeline] [ddd] echo
[ddd] build_if_needed: eee
[Pipeline] [ddd] }
[Pipeline] [eee] echo
[eee] build_if_needed: eee
[Pipeline] [eee] }
[Pipeline] // parallel
[Pipeline] End of Pipeline