I have made a class where I am going to store the duration of an event. As you see I have made fields for each but would it be better to save it as seconds and then calculate the hour, minute and seconds on the fly? The add method that I made would be simpler if I did so but are there any disadvantages?
public class Duration {
private int hours;
private int minutes;
private int seconds;
public Duration(int hours, int minutes, int seconds) {
setHours(hours);
setMinutes(minutes);
setSeconds(seconds);
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public int getMinutes() {
return minutes;
}
public void setMinutes(int minutes) {
this.minutes = minutes;
}
public int getSeconds() {
return seconds;
}
public void setSeconds(int seconds) {
this.seconds = seconds;
}
public void add(Duration duration) {
}
}
It would be much better to use an existing library, such as Joda.