Jump to content

Nautical bell: Difference between revisions

Add Seed7 example
m (→‎{{header|Java}}: just to be on the safe side)
(Add Seed7 example)
Line 730:
</pre>
 
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
include "time.s7i";
include "duration.s7i";
include "keybd.s7i";
 
const array string: watch is [] ("Middle", "Morning", "Forenoon", "Afternoon", "Dog", "First");
const array string: bells is [] ("One Bell", "Two Bells", "Three Bells", "Four Bells", "Five Bells", "Six Bells", "Seven Bells", "Eight Bells");
 
const func time: truncToHalfHour (in time: aTime) is func
result
var time: truncatedTime is time.value;
begin
truncatedTime := aTime;
truncatedTime.minute := aTime.minute div 30 * 30;
truncatedTime.second := 0;
truncatedTime.micro_second := 0;
end func;
 
const proc: main is func
local
var time: nextTime is time.value;
var time: midnight is time.value;
var integer: minutes is 0;
begin
writeln;
nextTime := truncToHalfHour(time(NOW));
midnight := truncToDay(nextTime);
while TRUE do
nextTime +:= 30 . MINUTES;
await(nextTime);
minutes := toMinutes(nextTime - midnight);
writeln(str_hh_mm(nextTime, ":") <& " - " <&
watch[succ((minutes - 30) mdiv 240 mod 6)] <& " watch - " <&
bells[succ((minutes - 30) mdiv 30 mod 8)] <& " Gone.");
flush(OUT);
end while;
end func;</lang>
 
{{out}}
<pre>
00:00 - First watch - Eight Bells Gone.
00:30 - Middle watch - One Bell Gone.
01:00 - Middle watch - Two Bells Gone.
01:30 - Middle watch - Three Bells Gone.
02:00 - Middle watch - Four Bells Gone.
02:30 - Middle watch - Five Bells Gone.
03:00 - Middle watch - Six Bells Gone.
03:30 - Middle watch - Seven Bells Gone.
04:00 - Middle watch - Eight Bells Gone.
04:30 - Morning watch - One Bell Gone.
05:00 - Morning watch - Two Bells Gone.
05:30 - Morning watch - Three Bells Gone.
06:00 - Morning watch - Four Bells Gone.
06:30 - Morning watch - Five Bells Gone.
07:00 - Morning watch - Six Bells Gone.
07:30 - Morning watch - Seven Bells Gone.
08:00 - Morning watch - Eight Bells Gone.
08:30 - Forenoon watch - One Bell Gone.
09:00 - Forenoon watch - Two Bells Gone.
09:30 - Forenoon watch - Three Bells Gone.
10:00 - Forenoon watch - Four Bells Gone.
10:30 - Forenoon watch - Five Bells Gone.
11:00 - Forenoon watch - Six Bells Gone.
11:30 - Forenoon watch - Seven Bells Gone.
12:00 - Forenoon watch - Eight Bells Gone.
12:30 - Afternoon watch - One Bell Gone.
13:00 - Afternoon watch - Two Bells Gone.
13:30 - Afternoon watch - Three Bells Gone.
14:00 - Afternoon watch - Four Bells Gone.
14:30 - Afternoon watch - Five Bells Gone.
15:00 - Afternoon watch - Six Bells Gone.
15:30 - Afternoon watch - Seven Bells Gone.
16:00 - Afternoon watch - Eight Bells Gone.
16:30 - Dog watch - One Bell Gone.
17:00 - Dog watch - Two Bells Gone.
17:30 - Dog watch - Three Bells Gone.
18:00 - Dog watch - Four Bells Gone.
18:30 - Dog watch - Five Bells Gone.
19:00 - Dog watch - Six Bells Gone.
19:30 - Dog watch - Seven Bells Gone.
20:00 - Dog watch - Eight Bells Gone.
20:30 - First watch - One Bell Gone.
21:00 - First watch - Two Bells Gone.
21:30 - First watch - Three Bells Gone.
22:00 - First watch - Four Bells Gone.
22:30 - First watch - Five Bells Gone.
23:00 - First watch - Six Bells Gone.
23:30 - First watch - Seven Bells Gone.
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.