Jamie Law Jamie Law - 2 months ago 10
Java Question

Java custom toString function error

Hey guys im very new to Java and im trying to make a student class to take in and print some values about a student, but i get a "Invalid Method Declaration" error on line 29 and i have no idea why.

I am trying to contain student creation data inside one function, and a tostring function in another method.

public class Student {

int ID;
int Age;
String Name;
double AvgLogin;


public Student(int ID,int Age,String Name,double AvgLogin)
{
this.ID = ID;
this.Age = Age;
this.Name = Name;
this.AvgLogin = AvgLogin;
}
public printer(int ID,string Name,int Age,double AvgLogin) {
System.out.println("Age : " + Age + " Average Login time : " + AvgLogin + "ID :" + ID +" Name : " + Name);





} //end method

public int getID() {
return ID;
}

public String getName() {
return Name;
}

public int getAge() {
return Age;
}

public void setAge(int Age) {
this.Age = Age;
}

public double getAvgLogin() {
return AvgLogin;
}

public void setAvgLogin(double AvgLogin) {
this.AvgLogin = AvgLogin;
}
}








//Student John = new Student(ID,Age,Name,AvgLogin)

Answer

you just missed the return type for your printer method. You should use the following code for your printer method.

public void printer(int ID,string Name,int Age,double AvgLogin) {
    System.out.println("Age : " + Age + " Average Login time : " + AvgLogin + "ID :" + ID +" Name : " + Name);
}
Comments