Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. -- [[ worker.lua ]]
  2. local Worker = {
  3. ["Name"] = "Worker"
  4. }
  5.  
  6. function Worker.new(class, name)
  7. return setmetatable({
  8. ClassName = rawget(class, "Name"),
  9. Name = name,
  10. Salary = 0,
  11. MonthsWorked = 0,
  12. Earnings = 0,
  13. }, class)
  14. end
  15.  
  16. function Worker:IsA(class)
  17. if self.ClassName == class then
  18. return true
  19. else
  20. return false
  21. end
  22. end
  23.  
  24. function Worker:GetPaid()
  25. self.Earnings = self.Earnings + self.Salary
  26. return self.Salary
  27. end
  28.  
  29. function Worker:GetFired()
  30. self.Salary = 1000
  31. self.ClassName = "Unemployed"
  32. setmetatable(self, Unemployed)
  33. end
  34.  
  35. Worker.__index = Worker
  36.  
  37. -- [[ manager.lua ]]
  38. local Manager = {
  39. ["Name"] = "Manager"
  40. }
  41.  
  42. function Manager:GetPromoted()
  43. if (math.random() <= 0.02) then
  44. self.Salary = self.Salary + 2000
  45. end
  46. end
  47.  
  48. Manager.__index = Manager
  49. setmetatable(Manager, {__index = Worker})
  50.  
  51. --[[ programmer.lua ]]
  52. local Programmer = {
  53. ["Name"] = "Programmer"
  54. }
  55.  
  56. function Programmer:GetBonus()
  57. if (math.random() <= 0.1) then
  58. self.Salary = self.Salary + (math.random(1000, 4000) + 1000)
  59. end
  60. end
  61.  
  62. Programmer.__index = Programmer
  63. setmetatable(Programmer, {__index = Worker})
  64.  
  65. --[[ unemployed.lua ]]
  66. local Unemployed = {
  67. ["Name"] = "Unemployed"
  68. }
  69.  
  70. function Unemployed:FindJob()
  71. if (math.random() <= 0.1) then
  72. self.ClassName = "Programmer"
  73. setmetatable(self, Programmer)
  74. end
  75. end
  76.  
  77. Unemployed.__index = Unemployed
  78. setmetatable(Unemployed, {__index = Unemployed})
  79.  
  80. --[[ start-work.lua ]]
  81. local PROJECT_NAME = "Working! Lab"
  82. local WORKER_COUNT = 20
  83. local MONTH_COUNT = 60
  84.  
  85. local names = {"Kelley", "Savanna", "Tania", "Lilith", "Zoey", "Laney", "Lora", "Kim", "Ava", "Bess"}
  86. local workers = {}
  87.  
  88. for i = 1, WORKER_COUNT do
  89. local name = names[math.random(1, #names)]
  90. local jobIndex = math.random()
  91.  
  92. if (jobIndex <= 0.1) then
  93. table.insert(workers, Worker.new(Manager, name))
  94. elseif (jobIndex <= 0.8) then
  95. table.insert(workers, Worker.new(Programmer, name))
  96. else
  97. table.insert(workers, Worker.new(Unemployed, name))
  98. end
  99. end
  100.  
  101. for month = 1, MONTH_COUNT do
  102. for index = 1, #workers do
  103. local worker = workers[index]
  104.  
  105. if worker:IsA("Manager") then
  106. worker:GetPromoted()
  107. elseif worker:IsA("Programmer") and (month % 12 == 0) then
  108. worker:GetBonus()
  109. else
  110. worker:FindJob()
  111. end
  112.  
  113. worker:GetPaid()
  114. end
  115. end
  116.  
  117. print("Over the duration of "..tostring(MONTH_COUNT).." months, the following occured:")
  118.  
  119. for index = 1, #workers do
  120. print(self.Name.. ", a "..self.ClassName..", made "..tostring(self.Earnings).." with her final salary of "..tostring(self.Salary).."!")
  121. print("She worked "..tostring(math.floor((self.MonthsWorked / MONTH_COUNT) * 100) / 100).." percent of the time.")
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement