-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathmain.go
63 lines (51 loc) · 1002 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
)
type toyota struct {
name string
price float64
discount float64
color string
}
func (t *toyota) showName() string {
return t.name
}
func (t *toyota) getPrice() float64 {
return t.price * t.discount
}
func (t *toyota) getDiscount() float64 {
return t.discount
}
func (t *toyota) getColor() string {
return t.color
}
func (t *toyota) setColor(color string) {
t.color = color
}
func (t toyota) updateColor(color string) {
t.color = color
}
func newCar(name string, price float64, discount float64, color string) *toyota {
return &toyota{
name: name,
price: price,
discount: discount,
color: color,
}
}
func main() {
car := &toyota{
name: "car1",
price: 4000,
discount: 0.8,
color: "white",
}
fmt.Println(car.getPrice())
car.updateColor("blue")
fmt.Println(car.getColor())
car.setColor("red")
fmt.Println(car.getColor())
car2 := newCar("car2", 6000, 0.7, "orange")
fmt.Println(car2.getColor())
}