-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteorology.go
62 lines (49 loc) · 1.21 KB
/
meteorology.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
package meteorology
import "fmt"
type TemperatureUnit int
const (
Celsius TemperatureUnit = 0
Fahrenheit TemperatureUnit = 1
)
// Add a String method to the TemperatureUnit type
func (sc TemperatureUnit) String() string {
units := []string{"°C", "°F"}
return units[sc]
}
type Temperature struct {
degree int
unit TemperatureUnit
}
// Add a String method to the Temperature type
func (d Temperature) String() string {
return fmt.Sprintf("%v %v", d.degree, d.unit)
}
type SpeedUnit int
const (
KmPerHour SpeedUnit = 0
MilesPerHour SpeedUnit = 1
)
// Add a String method to SpeedUnit
func (sc SpeedUnit) String() string {
units := []string{"km/h", "mph"}
return units[sc]
}
type Speed struct {
magnitude int
unit SpeedUnit
}
// Add a String method to Speed
func (d Speed) String() string {
return fmt.Sprintf("%v %v", d.magnitude, d.unit)
}
type MeteorologyData struct {
location string
temperature Temperature
windDirection string
windSpeed Speed
humidity int
}
// Add a String method to MeteorologyData
func (d MeteorologyData) String() string {
return fmt.Sprintf("%v: %v, Wind %v at %v, %v%% Humidity", d.location, d.temperature, d.windDirection, d.windSpeed, d.humidity)
}