Add method which calculates the amount of seconds that were needed to solve a DailySudoku object based on its "timeNeeded" attribute

This commit is contained in:
uykek 2020-05-28 00:25:12 +02:00
parent a015bd5597
commit 91f7cc6d2b

View file

@ -25,6 +25,20 @@ public class DailySudoku extends Level {
return timeNeeded;
}
public int getTimeNeededInSeconds() {
if (timeNeeded.matches("/d/d:/d/d:/d/d")) {
String[] timeInstances = timeNeeded.split(":");
int hourIndex = 0;
int minuteIndex = 1;
int secondIndex = 2;
int minutes = Integer.parseInt(timeInstances[hourIndex]) * 60 + Integer.parseInt(timeInstances[minuteIndex]);
return minutes * 60 + Integer.parseInt(timeInstances[secondIndex]);
}
return 0;
}
public void setTimeNeeded(String timeNeeded) {
this.timeNeeded = timeNeeded;
}