我收到编译器错误:
练习.java:47:错误:不兼容的类型时间 endTime = startTime.addMinutes(minutes);
^
必需:找到时间:无效 1 错误
我尝试使用的方法是这样的:
public void addMinutes(int mins) {
this.mins += mins;
if (this.mins >= 60) { // check if over
addHours(this.mins / 60);
this.mins = this.mins % 60;
}
}
我不确定为什么。
import java.util.*;
import java.io.*;
public class Exercise {
private String exercise;
private int minutes;
private Time startTime;
private Time endTime;
private int addedminutes;
public Exercise(String exercisetype, int m, Time start) {
this.exercise = exercisetype;
this.minutes = m;
this.startTime = start;
}
public String getType() {
return this.exercise;
}
public int getMinutes() {
return this.minutes;
}
public Time getStart() {
return this.startTime;
}
public Time getEnd() {
Time endTime = startTime.addMinutes(minutes);
return endTime;
}
public int addMinutes(int added) {
addedminutes = this.minutes + added;
return addedminutes;
}
public Time setStart(Time newstart) {
this.startTime = newstart;
return newstart;
}
public String toString() {
String startStandard = startTime.getStandard();
String endStandard = endTime.getStandard();
String toReturn = (this.exercise + " for " + this.minutes + " minutes," + " from " + startStandard + " to " + endStandard);
return toReturn;
}
public boolean equals(Exercise exTwo) {
return exercise == exTwo.exercise && minutes == exTwo.minutes && startTime == exTwo.startTime;
}
private static String exercisetype;
public static String getTypes() {
String types = ("Exercise types: " + Exercise.exercisetype);
return types;
}
}