forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toy.go
48 lines (40 loc) · 970 Bytes
/
toy.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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Package toy contains support for managing toy inventory.
package toy
// Toy represents a toy we sell.
type Toy struct {
Name string
Weight int
onHand int
sold int
}
// New creates values of type toy.
func New(name string, weight int) *Toy {
return &Toy{
Name: name,
Weight: weight,
}
}
// OnHand returns the current number of this
// toy on hand.
func (t *Toy) OnHand() int {
return t.onHand
}
// UpdateOnHand updates the on hand count and
// returns the current value.
func (t *Toy) UpdateOnHand(count int) int {
t.onHand = t.onHand + count
return t.onHand
}
// Sold returns the current number of this
// toy sold.
func (t *Toy) Sold() int {
return t.sold
}
// UpdateSold updates the sold count and
// returns the current value.
func (t *Toy) UpdateSold(count int) int {
t.sold = t.sold + count
return t.sold
}