Calendar - for "REAL" programmers: Difference between revisions

m (→‎{{header|360 Assembly}}: Superfluous blanks suppressed)
Line 819:
 
=={{header|Elena}}==
ELENA 3.x :
<lang elena>#import system.
<lang elena>#import system'text.
#import system'routines.
#import system'calendar.
Line 827:
#import extensions'routines.
 
#symbolconst MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
#symbolconst DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
 
#class CalendarMonthPrinter
{
#fieldobject theDate.
#fieldobject theLine.
#fieldobject theMonth.
#fieldobject theYear.
#fieldobject theRow.
#constructor new &year:aYear &month:aMonth
[
theMonth := aMonth.
Line 846:
]
 
#method writeTitle
[
theRow << set:0.
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1.
DayNames run &each: aName
Line 854:
]
#method writeLine
[
theLine clear.
if (theDate month == theMonth)
? [
theLine write:" " &length:(((theDate dayOfWeek) => 0 ? [ 7 ]; ! [ theDate dayOfWeek ]) - 1).
control do:
[
theLine write:(theDate day literal) &paddingLeft:3 &with:#32.
theDate := theDate add &days:1.
]
Line 870 ⟶ 871:
].
#var(type:int) aLength := theLine length.
if (aLength < 21)
? [ theLine write:" " &length:(21 - aLength). ].
theRow += 1.
]
#method iterator = Iterator
{
available = theRow < 7.
 
readIndex &vint:anIndex [ anIndex << set:theRow int. ]
 
write &index:anIndex
[
if (anIndex <= theRow)
? [ self$owner writeTitle. ].
#loopwhile (anIndex > theRow) ?
[ self$owner writeLine. ].
]
 
get = self$owner.
}.
#method printTitleTo : anOutput
[
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32.
]
#method printTo : anOutput
[
anOutput write:(theLine literal).
Line 905 ⟶ 907:
}
 
#class Calendar
{
#field(type:int) theYear.
#field(type:int) theRowLength.
#constructor new : aYear
[
theYear := aYear int.
Line 916 ⟶ 918:
]
#method printTo:anOutput
[
anOutput write:"[SNOOPY]" &padding:(theRowLength * 25) &with:#32.
Line 923 ⟶ 925:
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)
[ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]].
Line 934 ⟶ 936:
aMonth printTitleTo:anOutput.
anOutput write:" ".
].
anOutput writeLine.
Line 943 ⟶ 944:
[
aPrinter printTo:anOutput.
 
anOutput write:" ".
].
Line 950 ⟶ 952:
]
}
#symbol program =
 
#symbol program =
[
#var aCalender := Calendar new:(console write:"ENTER THE YEAR:" readLine:(Integer new)).
aCalender printTo:console.
Anonymous user