【发布时间】:2018-05-09 04:22:03
【问题描述】:
我对 Java 还很陌生,到目前为止只用它编程了几个月。
我有两个班级,TimeSlot 和 LabGroup。
TimeSlot 类中有代码--
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]);
}
然后在LabGroup 类中有代码--
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);
}
连同toString 方法--
public String toString() {
return "Group "+ charLabel + timeSpec+ "\n";
}
LabGroup 的示例输入是 "A Mon 13:00 15:00",然后应该通过 toString 给出输出 --
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
但我却得到了——
Group AlabExam1.TimeSlot@3f0fbfe5
, Group BlabExam1.TimeSlot@ea0e8b8
, Group ClabExam1.TimeSlot@25eab2ba
, Group DlabExam1.TimeSlot@37528b33
【问题讨论】:
标签: java class printing tostring