-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc2w3.go
56 lines (46 loc) · 768 Bytes
/
c2w3.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
package main
import (
"fmt"
)
type Animal struct{
food string
locomotion string
noise string
}
func (a *Animal) Eat() {
fmt.Printf("%s\n",a.food)
}
func (a *Animal) Speak() {
fmt.Printf("%s\n",a.noise)
}
func (a *Animal) Move() {
fmt.Printf("%s\n",a.locomotion)
}
func main(){
var a, v string;
var animalType Animal;
cow := Animal{"grass", "walk", "moo"}
bird := Animal{"worms", "fly", "peep"}
snake := Animal{"mice", "slither", "hsss"}
for {
fmt.Printf("> ")
fmt.Scan(&a)
fmt.Scan(&v)
switch a{
case "cow":
animalType = cow
case "bird":
animalType = bird
case "snake":
animalType = snake
}
switch v{
case "eat":
animalType.Eat()
case "move":
animalType.Move()
case "noise":
animalType.Speak()
}
}
}