3
this assignment is very hard to explain. i need to print out data that is loaded by a user, this info is saved into an array. i then need to print that info, so i made a toString method in my constructor class. now i need to call this method in my driver class. how do i do this, could u help me also with wut i put in my method header. here is my toStudent in my constructor., please explain how i call this method and print the info.
public String toString(){
String str ="";
str +="\nLast Name: " + getLastName();
str +="\nFirst Name: " + getFirstName();
str +="\nAddress: " + getAddress();
str +="\nCity: " + getCity();
str +="\nState: " + getState();
str +="\nZip: " + getZip();
str +="\nHome Phone: " + getHomePhone();
str +="\nCell Phone: " + getCellPhone();
str +="\nGPA: " + getGradePointAve();
return str;
}
Well, since that method has no parameters, you would just do this to call it
toString();
Since you have to put it into an array, it would be something like a for loop
for(int i = 0; i < num_elems; i++) //num_elems is the number of elements in the array{
array[i] = toString();
}
where array is an array of type String.
DOes that help?
Message was edited by:
Arkhan
thank you very much , that was very helpful.
i was also wondering, when i try to compile, it says class or "interface" expected on this line of code:
public static void quitStudent(Student [] students) {
System.out.println("Good Bye");
}//end quitStudent
whats wrong?
nevermind, i figured that out, but i have a new problem, haha, it says that toString is non static and cant be referenced from a non static context, what is that about,
public static Student printStudent (Student [] students) {
int totalStudents;
for(int i = 0; i < totalStudents; i++) {
students[i] = toString();
}//end for