Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
|
|
@ -0,0 +1,139 @@
|
|||
#define system.
|
||||
#define system'text.
|
||||
#define system'routines.
|
||||
#define system'calendar.
|
||||
#define extensions.
|
||||
#define extensions'math.
|
||||
#define extensions'routines.
|
||||
|
||||
// --- calendar ---
|
||||
|
||||
#symbol MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
|
||||
#symbol DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
|
||||
|
||||
#class CalendarMonthPrinter
|
||||
{
|
||||
#field theDate.
|
||||
#field theLine.
|
||||
#field theMonth.
|
||||
#field theYear.
|
||||
#field theRow.
|
||||
|
||||
#constructor new &Year:aYear &Month:aMonth
|
||||
[
|
||||
theMonth := aMonth.
|
||||
theYear := aYear.
|
||||
theLine := TextBuffer new.
|
||||
theRow := Integer new.
|
||||
]
|
||||
|
||||
#method firstLine : aDay
|
||||
[
|
||||
theRow << 0.
|
||||
theDate := Date new &Year:theYear &Month:theMonth &Day:aDay.
|
||||
control foreach:DayNames &do: aName
|
||||
[ theLine write:" " write:aName ].
|
||||
]
|
||||
|
||||
#method nextLine
|
||||
[
|
||||
theLine clear.
|
||||
|
||||
(theDate Month == theMonth)
|
||||
? [
|
||||
theLine~stringOp write:" " &length:(((theDate DayOfWeek) => 0 ? [ 7 ] ! [ theDate DayOfWeek ]) subtract:1 int).
|
||||
|
||||
control do:
|
||||
[
|
||||
theLine~stringOp write:(theDate Day) &paddingLeft:3 &with:" ".
|
||||
|
||||
theDate := theDate add &Days:1.
|
||||
]
|
||||
&until:[(theDate Month != theMonth)or:[theDate DayOfWeek == 1]].
|
||||
].
|
||||
|
||||
#var(type:int) aLength := theLine length.
|
||||
(aLength < 21)
|
||||
? [ theLine~stringOp write:" " &length:(21 - aLength). ].
|
||||
|
||||
theRow += 1.
|
||||
|
||||
^ theRow < 7.
|
||||
]
|
||||
|
||||
#method enumerator =
|
||||
{
|
||||
set &index:anIndex [ self firstLine:(anIndex + 1) ]
|
||||
|
||||
next [ ^ self nextLine. ]
|
||||
|
||||
get = self.
|
||||
}.
|
||||
|
||||
#method printTitleTo : anOutput
|
||||
[
|
||||
anOutput~stringOp write:(MonthNames @(theMonth - 1)) &padding:21 &with:" ".
|
||||
]
|
||||
|
||||
#method printTo : anOutput
|
||||
[
|
||||
anOutput write:(theLine literal).
|
||||
]
|
||||
}
|
||||
|
||||
#class Calendar
|
||||
{
|
||||
#field theYear.
|
||||
#field theRowLength.
|
||||
|
||||
#constructor new : aYear
|
||||
[
|
||||
theYear := aYear int.
|
||||
theRowLength := 3.
|
||||
]
|
||||
|
||||
#method printTo:anOutput
|
||||
[
|
||||
anOutput~stringOp write:"[SNOOPY]" &padding:(theRowLength * 25) &with:" " writeLine.
|
||||
anOutput~stringOp write:theYear &padding:(theRowLength * 25) &with:" " writeLine writeLine.
|
||||
|
||||
#var aRowCount := 12 / theRowLength.
|
||||
#var Months := matrixControl new &m:aRowCount &n:theRowLength &each: (:i:j) [ CalendarMonthPrinter new &Year:theYear &Month:(i * theRowLength + j + 1) ].
|
||||
|
||||
control foreach:Months &do: aRow
|
||||
[
|
||||
control foreach:aRow &do: aMonth
|
||||
[
|
||||
aMonth printTitleTo:anOutput.
|
||||
|
||||
anOutput write:" ".
|
||||
].
|
||||
|
||||
anOutput writeLine.
|
||||
|
||||
control for:(ParallelEnumerator new:aRow) &do: aLine
|
||||
[
|
||||
control foreach:aLine &do: aPrinter
|
||||
[
|
||||
aPrinter printTo:anOutput.
|
||||
|
||||
anOutput write:" ".
|
||||
].
|
||||
|
||||
anOutput writeLine.
|
||||
].
|
||||
].
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
// --- program ---
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var aCalender := Calendar new:(consoleEx write:"Enter the year:" readLine:(Integer new)).
|
||||
|
||||
aCalender printTo:consoleEx.
|
||||
|
||||
consoleEx readChar.
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue