-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (63 loc) · 1019 Bytes
/
main.go
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
package main
import "fmt"
type SalaryCalculator interface {
CalculateSalary() int
}
type permanent struct {
id int
basic int
bonus int
}
type contract struct {
id int
basic int
}
type freelancer struct {
id int
hours int
rate int
}
func main() {
p1 := permanent{
id: 1,
basic: 10000,
bonus: 2000,
}
p2 := permanent{
id: 2,
basic: 12000,
bonus: 3000,
}
c1 := contract{
id: 3,
basic: 8000,
}
f1 := freelancer{
id: 4,
hours: 20,
rate: 87,
}
f2 := freelancer{
id: 5,
hours: 10,
rate: 56,
}
employees := []SalaryCalculator{p1, p2, c1, f1, f2}
totalExpenses(employees)
}
func (p permanent) CalculateSalary() int {
return p.basic + p.bonus
}
func (c contract) CalculateSalary() int {
return c.basic
}
func (f freelancer) CalculateSalary() int {
return f.hours * f.rate
}
func totalExpenses(s []SalaryCalculator) {
expenses := 0
for _,v := range s {
expenses = expenses + v.CalculateSalary()
}
fmt.Println("Total expenses ", expenses)
}