/* Copyright (C) 2011-2023 Patrick H. E. Foubet - E2L Ivry Ecole du Logiciel Libre : https://e2li.org/ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see *******************************************************************/ package main import ( "fmt" "math" ) type Wheel struct { Circle Material string Color string X float64 } func (w Wheel) Info() { fmt.Printf("Une roue est faite en %s de couleur %s\n", w.Material, w.Color) } type Circle struct { X float64 Y float64 Radius float64 } type Shape interface { Area() float64 Area2() float64 } func (c *Circle) Area() float64 { return c.Radius * c.Radius * math.Pi } func (c Circle) Area2() float64 { return c.Radius * c.Radius * math.Pi } func Area(c Circle) float64 { return c.Radius * c.Radius * math.Pi } func ShapeArea(s Shape) float64 { return s.Area() } func main() { c1 := Circle{ X: 15.0, Y: 12.0, Radius: 8.5, } c2 := Circle{15.0, 12, 8.5} fmt.Println(c1 == c2) fmt.Println(c1.Area() == c1.Area2()) w1 := Wheel{ Circle: Circle{ Radius: 10.0, X: 15.0, }, Material: "Caoutchouc", Color: "Noire", X: 5.0, } w1.Info() fmt.Println(w1.Area()) fmt.Println(w1.X) fmt.Println(w1.Circle.X) }