Advertisement
tsounakis

season 2 finale

Oct 22nd, 2020
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.74 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "os"
  6.     "bufio"
  7.     "strings"
  8. )
  9.  
  10. type Animal interface {
  11.     Eat()
  12.     Move()
  13.     Speak()
  14. }
  15.  
  16.  
  17. type cow struct {}
  18.  
  19. type snake struct {}
  20.  
  21. type bird struct {}
  22.  
  23. func (c cow) Eat() {
  24.     fmt.Printf("grass\n>")
  25. }
  26.  
  27. func (c cow) Speak() {
  28.     fmt.Printf("moo\n>")
  29. }
  30.  
  31. func (c cow) Move() {
  32.     fmt.Printf("walk\n>")
  33. }
  34.  
  35. func (s snake) Eat() {
  36.     fmt.Printf("mice\n>")
  37. }
  38.  
  39. func (s snake) Speak() {
  40.     fmt.Printf("hsss\n>")
  41. }
  42.  
  43. func (s snake) Move() {
  44.     fmt.Printf("slither\n>")
  45. }
  46.  
  47. func (b bird) Eat() {
  48.     fmt.Printf("worms\n>")
  49. }
  50.  
  51. func (b bird) Speak() {
  52.     fmt.Printf("peep\n>")
  53. }
  54.  
  55. func (b bird) Move() {
  56.     fmt.Printf("fly\n>")
  57. }
  58.  
  59. func main() {
  60.     var inS []string
  61.     input := bufio.NewScanner(os.Stdin)
  62.     m := make(map[string]Animal)
  63.     Cow :=  cow{}
  64.     Bird := bird{}
  65.     Snake := snake{}
  66.  
  67.     fmt.Print(">")
  68.     for input.Scan() {
  69.         fmt.Printf(">")
  70.         inS = strings.Split(input.Text(), " ")
  71.         switch inS[0] {
  72.         case "newanimal": {
  73.             switch inS[2] {
  74.                 case "cow": {
  75.                     m[inS[1]] = Cow
  76.                     fmt.Printf("Created it!\n>")
  77.                     break
  78.                 }
  79.                 case "bird": {
  80.                     m[inS[1]] = Bird
  81.                     fmt.Printf("Created it!\n>")
  82.                     break
  83.                 }
  84.                 case "snake": {
  85.                     m[inS[1]] = Snake
  86.                     fmt.Printf("Created it!\n>")
  87.                     break
  88.                 }
  89.                 default: {
  90.                     fmt.Printf("Error. Type again.\n>")
  91.                     break
  92.                 }
  93.             }
  94.             break
  95.         }
  96.         case "query": {
  97.             switch inS[2] {
  98.                 case "eat": {
  99.                     m[inS[1]].Eat()
  100.                     break
  101.                 }
  102.                 case "move": {
  103.                     m[inS[1]].Move()
  104.                     break
  105.                 }
  106.                 case "speak": {
  107.                     m[inS[1]].Speak()
  108.                     break
  109.                 }
  110.                 default: {
  111.                     fmt.Printf("Error. Type again.\n>")
  112.                     break
  113.                 }
  114.             }
  115.             break
  116.         }
  117.         default: {
  118.             fmt.Printf("Error. Type again.\n>")
  119.             break
  120.         }
  121.     }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement