Calendar - for "REAL" programmers: Difference between revisions
Content added Content deleted
PatGarrett (talk | contribs) m (→{{header|360 Assembly}}: Superfluous blanks suppressed) |
|||
Line 819: | Line 819: | ||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 3.x : |
|||
<lang elena>#import system. |
|||
#import system'text. |
<lang elena>#import system'text. |
||
#import system'routines. |
#import system'routines. |
||
#import system'calendar. |
#import system'calendar. |
||
Line 827: | Line 827: | ||
#import extensions'routines. |
#import extensions'routines. |
||
const MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"). |
|||
const DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU"). |
|||
class CalendarMonthPrinter |
|||
{ |
{ |
||
object theDate. |
|||
object theLine. |
|||
object theMonth. |
|||
object theYear. |
|||
object theRow. |
|||
constructor new &year:aYear &month:aMonth |
|||
[ |
[ |
||
theMonth := aMonth. |
theMonth := aMonth. |
||
Line 846: | Line 846: | ||
] |
] |
||
writeTitle |
|||
[ |
[ |
||
theRow |
theRow set:0. |
||
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1. |
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1. |
||
DayNames run &each: aName |
DayNames run &each: aName |
||
Line 854: | Line 854: | ||
] |
] |
||
writeLine |
|||
[ |
[ |
||
theLine clear. |
theLine clear. |
||
(theDate month == theMonth) |
if (theDate month == theMonth) |
||
[ |
|||
theLine write:" " &length:(((theDate dayOfWeek) => 0 |
theLine write:" " &length:(((theDate dayOfWeek) => 0 [ 7 ]; ! [ theDate dayOfWeek ]) - 1). |
||
control do: |
control do: |
||
[ |
[ |
||
theLine write:(theDate day literal) &paddingLeft:3 &with:#32. |
theLine write:(theDate day literal) &paddingLeft:3 &with:#32. |
||
⚫ | |||
theDate := theDate add &days:1. |
theDate := theDate add &days:1. |
||
] |
] |
||
Line 870: | Line 871: | ||
]. |
]. |
||
int aLength := theLine length. |
|||
(aLength < 21) |
if (aLength < 21) |
||
[ theLine write:" " &length:(21 - aLength). ]. |
|||
theRow += 1. |
theRow += 1. |
||
] |
] |
||
iterator = Iterator |
|||
{ |
{ |
||
available = theRow < 7. |
available = theRow < 7. |
||
readIndex &vint:anIndex [ anIndex |
readIndex &vint:anIndex [ anIndex set:theRow. ] |
||
write &index:anIndex |
write &index:anIndex |
||
[ |
[ |
||
(anIndex <= theRow) |
if (anIndex <= theRow) |
||
[ $owner writeTitle. ]. |
|||
while (anIndex > theRow) |
|||
[ |
[ $owner writeLine. ]. |
||
] |
] |
||
get = |
get = $owner. |
||
}. |
}. |
||
printTitleTo : anOutput |
|||
[ |
[ |
||
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32. |
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32. |
||
] |
] |
||
printTo : anOutput |
|||
[ |
[ |
||
anOutput write:(theLine literal). |
anOutput write:(theLine literal). |
||
Line 905: | Line 907: | ||
} |
} |
||
class Calendar |
|||
{ |
{ |
||
int theYear. |
|||
int theRowLength. |
|||
constructor new : aYear |
|||
[ |
[ |
||
theYear := aYear int. |
theYear := aYear int. |
||
Line 916: | Line 918: | ||
] |
] |
||
printTo:anOutput |
|||
[ |
[ |
||
anOutput write:"[SNOOPY]" &padding:(theRowLength * 25) &with:#32. |
anOutput write:"[SNOOPY]" &padding:(theRowLength * 25) &with:#32. |
||
Line 923: | Line 925: | ||
anOutput writeLine writeLine. |
anOutput writeLine writeLine. |
||
var aRowCount := 12 / theRowLength. |
|||
var Months := Array new &length:aRowCount set &every:(&index:i) |
|||
[ Array new &length:theRowLength set &every:(&index:j) |
[ Array new &length:theRowLength set &every:(&index:j) |
||
[ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]]. |
[ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]]. |
||
Line 934: | Line 936: | ||
aMonth printTitleTo:anOutput. |
aMonth printTitleTo:anOutput. |
||
anOutput write:" ". |
anOutput write:" ". |
||
]. |
]. |
||
⚫ | |||
anOutput writeLine. |
anOutput writeLine. |
||
Line 943: | Line 944: | ||
[ |
[ |
||
aPrinter printTo:anOutput. |
aPrinter printTo:anOutput. |
||
anOutput write:" ". |
anOutput write:" ". |
||
]. |
]. |
||
Line 950: | Line 952: | ||
] |
] |
||
} |
} |
||
⚫ | |||
⚫ | |||
[ |
[ |
||
var aCalender := Calendar new:(console write:"ENTER THE YEAR:" readLine:(Integer new)). |
|||
aCalender printTo:console. |
aCalender printTo:console. |