Skip to content

Commit

Permalink
c2-m3
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangbits committed Jun 6, 2020
1 parent 2523eb0 commit 7c91b2a
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions c2-m3/animal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,25 @@ func (animal *Animal) Speak() {
}

func main() {
cow := Animal{food: "grass", locomotion: "walk", noise: "moo"}
bird := Animal{"worms", "fly", "peep"}
snake := Animal{"mice", "slither", "hsss"}
animals := map[string]Animal{
"cow": {food: "grass", locomotion: "walk", noise: "moo"},
"bird": {"worms", "fly", "peep"},
"snake": {"mice", "slither", "hsss"},
}

for {
var s1, s2 string
fmt.Println("Please input request as 2 strings seperate by a space")
fmt.Print(">")
fmt.Scan(&s1, &s2)
switch s1 {
case "cow":
switch s2 {
case "eat":
cow.Eat()
case "move":
cow.Move()
case "speak":
cow.Speak()
}
case "bird":
switch s2 {
case "eat":
bird.Eat()
case "move":
bird.Move()
case "speak":
bird.Speak()
}
case "snake":
switch s2 {
case "eat":
snake.Eat()
case "move":
snake.Move()
case "speak":
snake.Speak()
}

animal := animals[s1]
switch s2 {
case "eat":
animal.Eat()
case "move":
animal.Move()
case "speak":
animal.Speak()
}
}
}

0 comments on commit 7c91b2a

Please sign in to comment.