Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

55 lines
875 B

package main
import "fmt"
type Employee struct {
Id int
FirstName string
LastName string
}
type Developer struct {
Individual Employee
HourlyRate int
WorkWeek [7]int
}
type Weekday int
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
func main() {
d := Developer{Individual: Employee{Id: 1, FirstName: "Tony", LastName: "Stark"}, HourlyRate: 10}
d.LogHours(Monday, 8)
d.LogHours(Tuesday, 10)
fmt.Println("Hours worked on monday:", d.WorkWeek[Monday])
fmt.Println("Hours worked on tuesday:", d.WorkWeek[Tuesday])
fmt.Printf("Hours worked this week: %d\n", d.HoursWorked())
}
func (d *Developer) LogHours(day Weekday, hours int) {
d.WorkWeek[day] = hours
}
func (d *Developer) HoursWorked() int {
total := 0
for _, v := range d.WorkWeek {
total += v
}
return total
}