-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (30 loc) · 649 Bytes
/
main.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
package main
import (
"fmt"
"math"
)
type shape interface {
getArea() float64
}
type square struct {
sideLength float64
}
type triangle struct {
height float64
base float64
}
func main() {
s := square{sideLength:5}
t := triangle{base:5, height:6}
fmt.Println("The area of the square of side ", s.sideLength, " is ", s.getArea())
fmt.Println("The area of the triangle of base ", t.base, " and height ", t.height, " is ", t.getArea())
}
func (s square) getArea() float64 {
return math.Pow(s.sideLength, 2)
}
func (t triangle) getArea() float64 {
return t.base * t.height / 2
}
func printArea(s shape) {
fmt.Println(s.getArea())
}