/**
* get a formatted string with information about a competition.
*
* @return String String with information about a competition.
*
* The output should be in the following format:
* <pre>
* Rodent's Information:
* Rat RFID 787878787
* Gender: F
* Vaccination status: false
*
* Maze Information:
* Start Time: 00:00:00
* End Time: 01:00:05
* Actual Time: 01:00:05
* Contest Time: 00:59:30
* </pre>
*
*/
public String toString()
{
// your code here, replace the "X" and -9 with appropriate
// references to instance variables or calls to methods
String output = "Competition Description: " + this.desc
+ "\nCompetition Count: " + this.count + "\n";
output += "Competition Results:" + "\n";
// loop through the array from beginning to end of populated elements
for (int i = 0; i < this.nextPos; ++i)
{
this.results[i].getRFID();
this.results[i].getGender();
// get toString() for each result
return output;
}
大家好,我已经坚持写这个 toString 好几天了。有人可以帮我弄清楚如何编写一个循环来从头到尾显示数组中的所有元素。我只是一直卡住。如您所见,我已经开始编写一个循环,但现在我不知道它是否开始正确。谢谢!