Problem Statement
The children start evenly spaced around the circle, with the first child, A, located right next to a chair. The child who follows A as they walk around the circle is B, the one who follows B is C, etc. The children all start walking when the music starts at a speed that will get them all the way around the circle in 10 seconds. When the music stops, they each try to get to the nearest chair.
Create a class Musical that contains a method loser that is given n (the number
of children) and time (the number of seconds the music plays). The method
should return the name of the loser as a
It may be helpful to note that the child who is farther from any chair than each other child is always the loser.
Definition
- Class:
- Musical
- Method:
- loser
- Parameters:
- int, double
- Returns:
- String
- Method signature:
- String loser(int n, double time)
- (be sure your method is public)
Constraints
- n will be between 2 and 26 inclusive.
- time will be between 1.0 and 100.0 inclusive.
- For all values within 1.0 E-9 of time the same child would be the loser.
Examples
3
1.2
Returns: "B"
Starting from their original positions they walk for 1.2 seconds. When the music stops the closest chair to A is the first chair, the one he started at. Meanwhile B has moved to the point where now that chair is also the closest chair for him. But A is closer than B so B is the loser. (C is closest to the second chair and has no competition for that one.)
3
12.0
Returns: "A"
The children walk all the way around the circle and a little farther before the music stops. The situation is almost the same now as in the previous case, with A and B racing for the first chair, but this time A is farther away than B.
26
100.0
Returns: "N"
3
13.33333333
Returns: "A"
7
1.0
Returns: "G"
2
15.0
Returns: "A"
The 2 children start out with A next to the chair and B on the other side of the circle. After 15 seconds, they have gone around the circle one and a half times, so B is next to the chair and A is the loser.
2
97.5001
Returns: "B"
2
97.4999999
Returns: "A"
26
6.32
Returns: "S"
26
6.3333
Returns: "R"
26
30.0
Returns: "N"
3
95.01
Returns: "B"
6
6
Returns: "D"
5
5.01
Returns: "C"
4
4
Returns: "B"
3
3
Returns: "A"
2
2
Returns: "B"
11
93.11360627157264
Returns: "E"
4
82.43353272623155
Returns: "D"
16
94.73354925417038
Returns: "G"
12
48.85784498751542
Returns: "J"
2
68.07855395827394
Returns: "B"
20
70.8611484776482
Returns: "R"
19
3.801045115813053
Returns: "N"
21
59.67468011687829
Returns: "D"
12
50.81878818026858
Returns: "H"
2
5.035596525341242
Returns: "A"
6
8.703510843974115
Returns: "B"
6
45.57191009502199
Returns: "E"
20
48.72814037961462
Returns: "S"
22
2.4714514233909637
Returns: "H"
2
40.51384648826714
Returns: "B"
24
72.27015306351026
Returns: "H"
22
10.454591349893066
Returns: "M"
22
71.18307498198075
Returns: "A"
2
58.729590324359236
Returns: "B"
11
32.06796037119692
Returns: "F"
13
21.950078722452687
Returns: "C"
4
96.39913781226532
Returns: "C"
17
92.37193925720291
Returns: "M"
19
57.882195261500314
Returns: "G"
21
10.334375459755545
Returns: "R"
21
25.129838215553992
Returns: "F"
23
96.20017182231156
Returns: "U"
7
37.31630188409941
Returns: "B"
10
23.442684470686224
Returns: "E"
21
16.49982024781516
Returns: "L"
4
70.38569894825125
Returns: "C"
19
27.080594596354683
Returns: "O"
9
1.622759706506978
Returns: "C"
14
90.57025603905608
Returns: "L"
21
77.85968940211978
Returns: "Q"
12
83.75177773745783
Returns: "E"
14
29.063417048572123
Returns: "K"
18
81.3810101977034
Returns: "D"
21
3.902506663747165
Returns: "P"
4
62.26724378357364
Returns: "D"
9
7.886449303491099
Returns: "C"
9
15.858421492892282
Returns: "H"
17
84.88476130187354
Returns: "M"
20
63.7338434125554
Returns: "I"
25
24.89741776988311
Returns: "T"
26
67.84381998604206
Returns: "X"
14
43.04228911630176
Returns: "I"
16
43.574054990036345
Returns: "C"
24
60.76295388997509
Returns: "S"
3
51.419011033556586
Returns: "B"
23
56.0
Returns: "H"
25
99.98
Returns: "O"
2
5.0
Returns: "A"
23
89.37584682273902
Returns: "U"
3
12.0
Returns: "A"
26
1.0
Returns: "A"
14
57.5723
Returns: "J"
2
6.0
Returns: "A"