Split your task into smaller ones and then ask about a more specific problem. Have you programmed I/O in any language before?
I did well in C++. I understand the math part so i think i can do the actual conversions but i am having trouble with the using the test harness to pass in values. i have some code written, but it doesn't work. thank you
public class TimeSpan {
private int hour;
private int min;
private int sec;
public TimeSpan(){
hour = 0;
min = 0;
sec = 0;
}
public void setfromHours(int newHour){
hour = newHour;
}
public void setFromMinutes(int newMin){
min = newMin;
}
public void setfromSeconds(int newSec){
sec = newSec;
}
public double toHour(){
return hour + min/60 + sec/3600;
}
public double toMinutes(){
return hour * 60 + min + sec/60;
}
public int toSeconds(){
return hour*3600 + min*60 + sec;
}
public void increment(TimeSpan step){
hour = hour + step.hour;
min = min + step.min;
sec = sec + step.sec;
}
public void decrement(TimeSpan step){
hour = hour - step.hour;
min = min - step.min;
sec = sec - step.sec;
}
public int compare(TimeSpan step){
if (hour * 3600 + min * 60 + sec < step.hour * 3600 + step.min * 60+
step.sec){
return -1;
}
else if (hour*3600 + min*60 + sec > step.hour * 3600 + step.min * 60+
step.sec){
return 1;
}
else if (hour*3600 + min*60 + sec == step.hour * 3600 + step.min * 60+
step.sec){
return 0;
}
}
}
//test harness
public class T_TimeSpan {
public static void main(String[] args) {
int step;
TimeSpan ts=new TimeSpan();
ts.setFromMinutes(-372);
System.out.println(ts.toMinutes());
}
}