mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-13 16:51:17 +00:00
60 lines
811 B
Go
60 lines
811 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type employee interface {
|
|
getName() string
|
|
getSalary() int
|
|
}
|
|
|
|
type contractor struct {
|
|
name string
|
|
hourlyPay int
|
|
hoursPerYear int
|
|
}
|
|
|
|
func (c contractor) getName() string {
|
|
return c.name
|
|
}
|
|
|
|
// ?
|
|
|
|
// don't touch below this line
|
|
|
|
type fullTime struct {
|
|
name string
|
|
salary int
|
|
}
|
|
|
|
func (ft fullTime) getSalary() int {
|
|
return ft.salary
|
|
}
|
|
|
|
func (ft fullTime) getName() string {
|
|
return ft.name
|
|
}
|
|
|
|
func test(e employee) {
|
|
fmt.Println(e.getName(), e.getSalary())
|
|
fmt.Println("====================================")
|
|
}
|
|
|
|
func main() {
|
|
test(fullTime{
|
|
name: "Jack",
|
|
salary: 50000,
|
|
})
|
|
test(contractor{
|
|
name: "Bob",
|
|
hourlyPay: 100,
|
|
hoursPerYear: 73,
|
|
})
|
|
test(contractor{
|
|
name: "Jill",
|
|
hourlyPay: 872,
|
|
hoursPerYear: 982,
|
|
})
|
|
}
|