since Jun 06, 2005

For More

Cows and Likes

Cows

Total received

0

In last 30 days

0

Total given

0

Likes

Total received

0

Received in last 30 days

0

Total given

0

Given in last 30 days

0

Forums and Threads

Scavenger Hunt

Ranch Hand Scavenger Hunt

Greenhorn Scavenger Hunt

I made some changes and got the result. The changed code is:

public class TimeInterval {

/** constructs an object that computes the time interval between two times

* @param aTime the first time@param anotherTime the second time */

public TimeInterval(int aTime, int anotherTime) {

time1 = aTime;

time2 = anotherTime;

intervalTime = 0;

hours = 0;

}

/** computes for the number of hours of interval less the minutes

* @return interval in hours */

public double getHours() {

if (time1 != time2) {

System.out.println("max =" + Math.max(time1, time2));

System.out.println("min =" + Math.min(time1, time2));

double timea = (Math.max(time1, time2)) / 100;

double timeb = (Math.min(time1, time2)) / 100;

System.out.println("timea =" + timea);

System.out.println("timeb =" + timeb);

int hour1 = (int)timea;

double remMin1 = (timea - hour1) * 100;

int hourMin1 = hour1 * 60;

timea = hourMin1 + remMin1;

/*hour1 = hour1 * 60;

time1 = hour1 + remMin1;Commented from original code*/

int hour2 = (int)timeb;

double remMin2 = (timeb - hour2) * 100;

int hourMin2 = hour2 * 60;

timeb = hourMin2 + remMin2;

/*double remMin2 = (timeb - hour2) * 100;

hour2 = hour2 * 60;

time2 = hour2 + remMin2;

intervalTime = (time1 - time2) / 100;Commented from original code*/

intervalTime = (timea - timeb) / 60;

System.out.println("intervalTime =" + intervalTime);

return hours = (int)intervalTime;

} else {

hours = 0;

intervalTime = 0;

return hours;

}

}

/** computes the number of minutes excess of one hour of interval

* @return interval minutes */

public double getMinutes() {

minutes = (intervalTime - hours ) * 60;

return minutes;

}

public double totalTime() {

totaltime = ((hours * 60) + minutes) / 60;

return totaltime;

}

private double intervalTime, time1, time2, totaltime, minutes;

private int hours;

}

I got fairly good results. One thing to note is you should not give inputs in three digits as 200 or 210 as time is always in four digits.

I put some output statements for tracking some outputs.

Here I have one question: When I give input as 2100 and 0100

I got output of Math.min(2100, 0100) as 64.0?

I don't why? If anybody can then please explain.

public class TimeInterval {

/** constructs an object that computes the time interval between two times

* @param aTime the first time@param anotherTime the second time */

public TimeInterval(int aTime, int anotherTime) {

time1 = aTime;

time2 = anotherTime;

intervalTime = 0;

hours = 0;

}

/** computes for the number of hours of interval less the minutes

* @return interval in hours */

public double getHours() {

if (time1 != time2) {

System.out.println("max =" + Math.max(time1, time2));

System.out.println("min =" + Math.min(time1, time2));

double timea = (Math.max(time1, time2)) / 100;

double timeb = (Math.min(time1, time2)) / 100;

System.out.println("timea =" + timea);

System.out.println("timeb =" + timeb);

int hour1 = (int)timea;

double remMin1 = (timea - hour1) * 100;

int hourMin1 = hour1 * 60;

timea = hourMin1 + remMin1;

/*hour1 = hour1 * 60;

time1 = hour1 + remMin1;Commented from original code*/

int hour2 = (int)timeb;

double remMin2 = (timeb - hour2) * 100;

int hourMin2 = hour2 * 60;

timeb = hourMin2 + remMin2;

/*double remMin2 = (timeb - hour2) * 100;

hour2 = hour2 * 60;

time2 = hour2 + remMin2;

intervalTime = (time1 - time2) / 100;Commented from original code*/

intervalTime = (timea - timeb) / 60;

System.out.println("intervalTime =" + intervalTime);

return hours = (int)intervalTime;

} else {

hours = 0;

intervalTime = 0;

return hours;

}

}

/** computes the number of minutes excess of one hour of interval

* @return interval minutes */

public double getMinutes() {

minutes = (intervalTime - hours ) * 60;

return minutes;

}

public double totalTime() {

totaltime = ((hours * 60) + minutes) / 60;

return totaltime;

}

private double intervalTime, time1, time2, totaltime, minutes;

private int hours;

}

I got fairly good results. One thing to note is you should not give inputs in three digits as 200 or 210 as time is always in four digits.

I put some output statements for tracking some outputs.

Here I have one question: When I give input as 2100 and 0100

I got output of Math.min(2100, 0100) as 64.0?

I don't why? If anybody can then please explain.

17 years ago