Skip to content

Instantly share code, notes, and snippets.

@luandevpro

luandevpro/main.go

Created Aug 2, 2020
Embed
What would you like to do?
package main
import (
"fmt"
)
type SalaryCalculator interface {
salaryCalculator() int
}
type Permanent struct {
id int
basic int
pf int
}
type Contract struct {
id int
basic int
}
func (p Permanent) salaryCalculator() int {
return p.basic + p.pf
}
func (c Contract) salaryCalculator() int {
return c.basic
}
func totalEx(s []SalaryCalculator) int {
ex := 0
for _, v := range s {
ex = ex + v.salaryCalculator()
}
return ex
}
func main() {
per1 := Permanent{1, 600, 100}
per2 := Permanent{2, 600, 50}
con1 := Contract{3, 300}
total := []SalaryCalculator{per1, per2, con1}
fmt.Println(totalEx(total))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.