Files
learngo/interfaces/composition/product.go

28 lines
489 B
Go
Raw Normal View History

2019-08-27 15:21:17 +03:00
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
type product struct {
2019-08-30 00:49:27 +03:00
Title string
Price money
2019-08-27 15:21:17 +03:00
}
func (p *product) discount(ratio float64) {
2019-08-30 00:49:27 +03:00
p.Price *= money(1 - ratio)
2019-08-27 15:21:17 +03:00
}
func (p *product) sum() money {
2019-08-30 00:49:27 +03:00
return p.Price
2019-08-27 15:21:17 +03:00
}
func (p *product) String() string {
2019-08-30 00:49:27 +03:00
return fmt.Sprintf("%-15s: %s", p.Title, p.Price)
2019-08-27 15:21:17 +03:00
}