You can create a method in your class called 'isBetween' that returns if the object is between passed startTime and endTime:
public class Running {
private double startTime;
private double endTime;
public Running(double startTime, double endTime) {
this.startTime = startTime;
this.endTime = endTime;
}
public boolean isBetween(int startTime, int endTime) {
return return startTime>=this.startTime && endTime<=this.endTime && startTime<=endTime;
}
@Override
public String toString() {
return "Start time: " + this.startTime + " End time: " + this.endTime ;
}
}
And in your main method, you can verify if only one object is between two times, or if all objects in a list are between two given numbers:
public static void main(String[] args) {
Running runningA = new Running(1, 10);
Running runningB = new Running(5,9);
Running runningC = new Running(4, 8);
List<Running> list = new ArrayList<>();
list.add(runningA);
list.add(runningB);
list.add(runningC);
// for only one object:
System.out.println(runningA.isBetween(5, 8)); //print true if object is between 5 and 8
// for all objects in a list:
list.stream().filter(n -> n.isBetween(5, 8)).forEach(System.out::println); //print all objects between 5 and 8
}