0

How do I call print() from the STudent class? I tried creating Student test = new Student() but that tells me the constructor type cannot be applied to given types.

The error I get in Netbeans is Required String, string, string, string, int, int, int, int. found no arguments actual and form arguments differ in length.

public class Roster {    

    print_all();

}

public static void print_all(){
    testStudents.stream().forEach((w) -> {
        Student.print();
    });
}



public class Student {

    public Student(String id, String firstName, String lastName, String email, int age, int grade01, int grade02, int grade03)
        public void print() {
            System.out.println("Student ID: " + 
                getId() + "\t First Name: " + 
                getFirstName() + "\t Last Name: " +  
                getLastName() +  "\t Age: " + 
                getAge() + "\t Grades: " + 
                getGradesArray() 
            );
    }
}
ragingasiancoder
  • 616
  • 6
  • 17
BlahBlah
  • 9
  • 1
  • This is probably an error when you try to initialize a `Student` object. Also, is this your entire `Student` class, because if so, then you don't have a constructor and member variables to store your id, name, etc. – ragingasiancoder Jul 22 '16 at 17:37
  • related: see [“Non-static method cannot be referenced from a static context” error](http://stackoverflow.com/q/4922145/217324). in addition to that you seem to have trouble with the idea of what a constructor is and how to define one. – Nathan Hughes Jul 22 '16 at 17:49

1 Answers1

0

The error I get in Netbeans is Required String, string, string, string, int, int, int, int. found no arguments actual and form arguments differ in length.

That is because you're trying to instantiate a new Student but you're not passing any parameter. If you want to be able to create a new Student with no parameters you need to implement a new empty constructor, like this:

public Student() {

}

And i think that you're missing the attributes in the Student class aswell, but i don't know if that's your whole class or not. Implement those and if you're using Eclipse, you can generate an Override of the toString() method, which is basically used to do what you want, print information to the screen.

It should look something like this:

@Override
public String toString() {
    return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email
            + ", age=" + age + ", grade1=" + grade1 + ", grade2=" + grade2 + ", grade3=" + grade3 + "]";
}
Julian
  • 344
  • 1
  • 11