-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayroll.rb
95 lines (69 loc) · 1.95 KB
/
payroll.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'pry'
class Employee
attr_reader :name, :email
def initialize(name, email)
@name = name
@email = email
end
end
class HourlyEmployee < Employee
attr_reader(:hourly_rate,:hours_worked)
def initialize(name, email, hourly_rate, hours_worked = 40)
@name = name
@email = email
@hourly_rate = hourly_rate
@hours_worked = hours_worked
end
def calculate_salary()
weekly_salary = @hourly_rate * @hours_worked
puts "Weekly salary #{weekly_salary}"
end
end
class SalariedEmployee < Employee
attr_reader(:year_salary)
def initialize(name,email,year_salary)
@name = name
@email = email
@year_salary = year_salary
end
def calculate_salary()
weekly_salary = @year_salary/52
puts "Weekly salary #{weekly_salary}"
end
end
class MultiPaymentEmployee < Employee
attr_reader(:year_salary,:hours_worked,:extrapay)
def initialize(name,email,year_salary,extrapay,hours_worked)
@name = name
@email = email
@year_salary = year_salary
@hours_worked = hours_worked
@extrapay = extrapay
end
def calculate_salary
if hours_worked > 40
weekly_salary = (@year_salary/52) + ((@hours_worked - 40) * extrapay)
else
weekly_salary = @year_salary/52
end
puts "Weekly salary #{weekly_salary}"
end
end
class Payroll
attr_reader :employees
def initialize(employees)
@employees = employees
end
def pay_employees
@employees.each {|i| binding.pry puts i.name
puts i.calculate_salary}
end
end
carlos = HourlyEmployee.new('Carlos', '[email protected]', 15)
erica = HourlyEmployee.new('Erica', '[email protected]', 15)
josh = HourlyEmployee.new('Josh', '[email protected]', 35, 50)
nizar = SalariedEmployee.new('Nizar', '[email protected]', 1000000)
ted = MultiPaymentEmployee.new('Ted', '[email protected]', 60000, 275, 55)
employees = [josh, nizar, ted, erica, carlos]
payroll = Payroll.new(employees)
payroll.pay_employees