Ich bin ziemlich neu in Java, nur für ein paar Monate mit ihm bisher programmiert.Java Fehler bei der Rückkehr mit einer toString-Funktion
Ich habe zwei Klassen, TimeSlot
und LabGroup
.
In der TimeSlot
Klasse gibt es die code--
private Time start;
private Time end;
private String day;
public TimeSlot(String spec) {
//splits given string on each space
String[] splitSpec = spec.split(" ");
day = splitSpec[0];
//uses the class Time, and passes in the hour and the minute of the time the lab begins.
this.start = new Time(splitSpec[1]);
//uses the class Time, and passes in the hour and the minute of the time the lab finishes.
this.end = new Time(splitSpec[2]);
}
Dann in der LabGroup
Klasse gibt die code-- ist
public String charLabel;
public TimeSlot timeSpec;
public String lineTime;
public LabGroup(String line) {
String[] lineSplit = line.split(" ");
charLabel = lineSplit[0];
//string a = "Day StartTime EndTime"
String a = lineSplit[1] + " " + lineSplit[2] + " " + lineSplit[3];
timeSpec = new TimeSlot(a);
}
zusammen mit einem toString
method--
public String toString() {
return "Group "+ charLabel + timeSpec+ "\n";
}
Ein Beispiel Eingabe in die LabGroup
wäre "A Mon 13:00 15:00"
und sollte dann die Ausgabe geben, durch die toString
, der -
Group A Mon 13:00 - 15:00
Group B Mon 15:00 - 17:00
Group C Tue 13:00 - 15:00
Group D Tue 15:00 - 17:00
Aber anstatt bin ich getting--
Group [email protected]
, Group [email protected]
, Group [email protected]
, Group [email protected]