Sunday 8 October 2017

Hours, Minutes and Seconds!!!

Hey people, I am having a doubt here, a puerile one!

There is a clock that is 24 hours format and every other property of the clock is as same as the other regular 12 hours format wall clock.

So I am not able to fix this formula to calculate the "Angle between the hour hand, the minute hand and the second hand".

Please look at the code and someone help me fix this.

import java.util.Scanner;

class Solution {
public static void main(String[] args) {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
int testCases = scanner.nextInt();
String[] time1 = new String[3];
String[] time2 = new String[3];
String[] input = new String[testCases];
for(int i = 0; i < testCases; i++) {
input[i] = scanner.next();
}
for(int i = 1; i < testCases; i++) {
time1 = input[i-1].split(":");
time2 = input[i].split(":");
String res = String.format("%.6f %.6f %.6f",
(Math.abs(Float.parseFloat(time2[0]) - Float.parseFloat(time1[0])) * 6),
(Math.abs(Float.parseFloat(time2[1]) - Float.parseFloat(time1[1])) * 6),
(Math.abs(Float.parseFloat(time2[2]) - Float.parseFloat(time1[2])) * 6)
);
System.out.println(res);
}
} catch (Exception exception){
exception.printStackTrace();
} finally {
scanner.close();
}
}
}


The output of the program should be the angle between the hour hand, minute hand and the second hand with respect to the one succeeding it.

For example, consider...

2
10:00:00
12:00:00

is given as the input. In this case, since we can simply calculate that the hour hand has traversed 30 degrees and the hour and minute hand has traversed 0 degree and 0 degree respectively. The output would be

30.000000 0.000000 0.000000

Please help me make a formula for it!

In  case of further clarification, please feel free to clarify!

Thanks a lot in advance! :)

No comments:

Post a Comment