I just wrote and tested this awesome method for my capstone. It really shows me that those seemingly pointless excecise problems can come in handy.
public String getFinishTime()
{
Time now = new Time();
Time finish = new Time();
now.setToNow();
int hr, mins, carry = 0, pm = 0;
hr = now.hour;
mins = now.minute;
if(hr > 11) {
pm = 1;
hr = hr%12;
}
int task_time = 0;
int hours, minutes;
for (int i = 0; i < tasks.size(); i++) {
task_time += tasks.get(i).getTime();
}
hours = (int) task_time / 60;
minutes = task_time % 60;
//TODO:time will be lost if hours is over 12
//hr = Integer.parseInt(now.format("%k"));
//mins = Integer.parseInt(now.format("%M"));
int fin_min, fin_hr;
if(mins+minutes > 59) {
carry++;
fin_min = (mins+minutes)%60;
} else {
fin_min = mins+minutes;
}
if(hr+hours+carry > 12) {
if(pm == 1)
pm =0;
fin_hr = (hr+hours+carry)%12;
} else {
fin_hr = hr+hours+carry;
}
String am = "";
if(pm == 1)
am = "pm";
if(pm == 0)
am = "am";
//hr += hours;
//mins += minutes;
//return hr+":"+mins+"," + hours+":"+minutes+","+fin_hr+":"+fin_min;
return fin_hr+":"+ ((fin_min < 10) ? "0"+fin_min : fin_min) + am;
}