Calendar - for "REAL" programmers: Difference between revisions

Content added Content deleted
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.


#symbol MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
const MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
#symbol DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
const DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").


#class CalendarMonthPrinter
class CalendarMonthPrinter
{
{
#field theDate.
object theDate.
#field theLine.
object theLine.
#field theMonth.
object theMonth.
#field theYear.
object theYear.
#field theRow.
object theRow.
#constructor new &year:aYear &month:aMonth
constructor new &year:aYear &month:aMonth
[
[
theMonth := aMonth.
theMonth := aMonth.
Line 846: Line 846:
]
]


#method writeTitle
writeTitle
[
[
theRow << 0.
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:
]
]
#method writeLine
writeLine
[
[
theLine clear.
theLine clear.
(theDate month == theMonth)
if (theDate month == theMonth)
? [
[
theLine write:" " &length:(((theDate dayOfWeek) => 0 ? [ 7 ] ! [ theDate dayOfWeek ]) - 1).
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:
].
].
#var(type:int) aLength := theLine length.
int aLength := theLine length.
(aLength < 21)
if (aLength < 21)
? [ theLine write:" " &length:(21 - aLength). ].
[ theLine write:" " &length:(21 - aLength). ].
theRow += 1.
theRow += 1.
]
]
#method iterator = Iterator
iterator = Iterator
{
{
available = theRow < 7.
available = theRow < 7.


readIndex &vint:anIndex [ anIndex << theRow int. ]
readIndex &vint:anIndex [ anIndex set:theRow. ]


write &index:anIndex
write &index:anIndex
[
[
(anIndex <= theRow)
if (anIndex <= theRow)
? [ self writeTitle. ].
[ $owner writeTitle. ].
#loop (anIndex > theRow) ?
while (anIndex > theRow)
[ self writeLine. ].
[ $owner writeLine. ].
]
]

get = self.
get = $owner.
}.
}.
#method printTitleTo : anOutput
printTitleTo : anOutput
[
[
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32.
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#32.
]
]
#method printTo : anOutput
printTo : anOutput
[
[
anOutput write:(theLine literal).
anOutput write:(theLine literal).
Line 905: Line 907:
}
}


#class Calendar
class Calendar
{
{
#field(type:int) theYear.
int theYear.
#field(type:int) theRowLength.
int theRowLength.
#constructor new : aYear
constructor new : aYear
[
[
theYear := aYear int.
theYear := aYear int.
Line 916: Line 918:
]
]
#method printTo:anOutput
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 aRowCount := 12 / theRowLength.
#var Months := Array new &length:aRowCount set &every:(&index:i)
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:
]
]
}
}
program =

#symbol program =
[
[
#var aCalender := Calendar new:(console write:"ENTER THE YEAR:" readLine:(Integer new)).
var aCalender := Calendar new:(console write:"ENTER THE YEAR:" readLine:(Integer new)).
aCalender printTo:console.
aCalender printTo:console.