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;

}

[1281 byte] By [redzone646a] at [2007-10-3 8:10:49]
# 1
You really are a fucking mòron aren't you.Triple posted now! Do not reply!
floundera at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...
# 2

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

Arkhana at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...
# 3
What part of "Do not reply" didn't you understand?
floundera at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...
# 4

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?

redzone646a at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...
# 5

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

redzone646a at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...
# 6
> You really are a fucking m騬on aren't you.That would be an evolutionary step up for the OP....> Triple posted now! Do not reply!
Java_Jaya at 2007-7-15 3:15:14 > top of Java-index,Java Essentials,New To Java...