Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TimeManager = {}
- do
- function TimeManager:new(o)
- local o = o or {}
- setmetatable(o, self)
- self.__index = self
- return o
- end
- function TimeManager:setTime(t)
- if type(t) == 'table' then
- self._selftime = (t[1] or 0) + (t[2] or 0) * 60 + (t[3] or 0) * 60 * 24
- elseif type(t) == 'number' then
- self._selftime = t
- else
- error('Wrong parameter!')
- end
- return self
- end
- function TimeManager:asNumber()
- return self._selftime
- end
- function TimeManager:asAcademicNumber()
- return self._selftime / 0.75
- end
- function TimeManager:asTime()
- local tbl = {}
- tbl[1] = math.floor(self._selftime % 60)
- tbl[2] = math.floor(self._selftime / 60) % 24
- tbl[3] = math.floor(math.floor(self._selftime / 60) / 24)
- return tbl
- end
- function TimeManager:toStringFull()
- local tbl = self:asTime()
- d = tostring(tbl[3])
- h = tostring(tbl[2])
- m = tostring(tbl[1])
- return form(d) .. ':' .. form(h) .. ':' .. form(m)
- end
- function TimeManager:toString()
- local tbl = self:asTime()
- h = tostring(tbl[2])
- m = tostring(tbl[1])
- return form(h) .. ':' .. form(m)
- end
- function TimeManager:addTime(t)
- local mins = 0
- if type(t) == 'table' then
- mins = ((TimeManager:new()):setTime(t)):asNumber()
- elseif type(t) == 'number' then
- mins = t
- else
- error('Wrong parameter!')
- end
- self._selftime = self._selftime + mins
- end
- function TimeManager.__lt(op1, op2)
- if tostring(op1) == 'TimeManager' and tostring(op2) == 'TimeManager' then
- return op1._selftime < op2._selftime
- elseif tostring(op1) == 'TimeManager' and type(op2) == 'number' then
- return op1._selftime < op2
- end
- return false
- end
- function TimeManager.__gt(op1, op2)
- if tostring(op1) == 'TimeManager' and tostring(op2) == 'TimeManager' then
- return op1._selftime > op2._selftime
- elseif tostring(op1) == 'TimeManager' and type(op2) == 'number' then
- return op1._selftime > op2
- end
- return false
- end
- function TimeManager.__add(op1, op2)
- local res = TimeManager:new()
- if tostring(op1) == 'TimeManager' and tostring(op2) == 'TimeManager' then
- res:setTime(op1:asNumber() + op2:asNumber())
- elseif tostring(op1) == 'TimeManager' and type(op2) == 'number' then
- res:setTime(op1:asNumber() + op2)
- else
- error('Wrong operands')
- end
- return res
- end
- function TimeManager.__sub(op1, op2)
- local res = TimeManager:new()
- if tostring(op1) == 'TimeManager' and tostring(op2) == 'TimeManager' then
- res:setTime(op1:asNumber() - op2:asNumber())
- elseif tostring(op1) == 'TimeManager' and type(op2) == 'number' then
- res:setTime(op1:asNumber() - op2)
- else
- error('Wrong operands')
- end
- return res
- end
- function TimeManager.__tostring()
- return "TimeManager"
- end
- function form(str)
- return ((#str == 0) and '00' or ((#str == 1) and '0' or '')) .. str
- end
- function createManager(t)
- local mng = TimeManager:new()
- mng:setTime(t)
- return mng
- end
- function timeToMin(t)
- local mng = TimeManager:new()
- mng:setTime(t)
- return mng:asNumber()
- end
- function minToTime(t)
- local mng = TimeManager:new()
- mng:setTime(t)
- return mng:asTime()
- end
- function mtToString(t)
- local mng = TimeManager:new()
- mng:setTime(t)
- return mng:toString()
- end
- end
- course = {
- {"Brief", 15},
- {"Java Technology", 15},
- {"NetBeans Development + Exercise", 30},
- {"Java Specials", 5 },
- {"Primitive types and literals", 15},
- {"Variables", 15},
- {"------------Exercise", 30},
- {"Operations", 10},
- {"java.lang", 10},
- {"------------Exercise", 30},
- {"Strings", 10},
- {"Arrays", 15},
- {"------------Exercise", 30},
- {"Input/Output", 15},
- {"Branching", 15},
- {"Cycles", 15},
- {"------------Exercise", 30},
- {"Methods", 15},
- {"Reference Types", 5 },
- {"------------Exercise", 30},
- {"Class", 15},
- {"------------Exercise", 30},
- {"Encapsulation", 10},
- {"Static Members", 10},
- {"Enumerations", 10},
- {"------------Exercise", 60},
- {"Packages", 15},
- {"Inheritance", 15},
- {"Polymorphism", 15},
- {"------------Exercise", 60},
- {"Interfaces", 15},
- {"Abstract classes", 10},
- {"------------Exercise", 60},
- {"Nested classes", 10},
- {"Exceptions", 10},
- {"Collections", 10},
- {"------------Exercise", 60}
- }
- manager = TimeManager:new()
- hours = timeToMin({0, 4});
- cof_each = timeToMin({0, 2});
- cof_max = 1
- cof_time = 15;
- start_time = timeToMin({0, 10})
- delta_time = 0
- do
- local last_break = start_time
- local cof_count = 0
- local time_count = 0
- local day_count = 1
- manager:setTime(start_time)
- print('---------' .. '[Day' .. day_count .. ']' .. '---------')
- for _, v in pairs(course) do
- if ((manager + (v[2] + (v[3] or 0) - delta_time)) - start_time):asNumber() > hours then
- time_count = time_count + manager:asNumber() - start_time
- manager:setTime(start_time)
- cof_count = 0
- last_break = start_time
- --add new day separator
- day_count = day_count + 1
- print('---------' .. '[Day' .. day_count .. ']' .. '---------')
- --add new day brief
- print(manager:toString() .. " - " .. (manager + 10):toString() .. " " .. "New day Brief")
- manager:addTime(10)
- end
- if (manager:asNumber() + v[2]) > last_break + cof_each and cof_count < cof_max then
- print(manager:toString() .. " - " .. (manager + cof_time):toString() .. " " .. "Coffe break")
- manager:addTime(cof_time)
- last_break = manager:asNumber()
- cof_count = cof_count + 1
- end
- if #v == 2 then
- print(manager:toString() .. " - " .. (manager + v[2]):toString() .. " " .. v[1])
- manager:addTime(v[2])
- elseif #v == 3 then --for a case when table have additional exercise time
- print(manager:toString() .. " - " .. (manager + v[2]):toString() .. " " .. v[1])
- manager:addTime(v[2])
- print(manager:toString() .. " – " .. (manager + v[3]):toString() .. " Exercise " .. v[1])
- manager:addTime(v[3])
- end
- end
- time_count = time_count + manager:asNumber() - start_time
- print("Total hours: " .. mtToString(time_count))
- end
Advertisement
Add Comment
Please, Sign In to add comment