-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoComparisonIfEx.go
33 lines (28 loc) · 1.01 KB
/
goComparisonIfEx.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
package main
import "fmt"
// NeedsLicense determines whether a license is needed to drive a type of vehicle. Only "car" and "truck" require a license.
func NeedsLicense(kind string) bool {
return kind == "car" || kind == "truck"
}
// ChooseVehicle recommends a vehicle for selection. It always recommends the vehicle that comes first in lexicographical order.
func ChooseVehicle(option1, option2 string) string {
if option1 > option2 {
return option2 + " is clearly the better choice."
}
return option1 + " is clearly the better choice."
}
// CalculateResellPrice calculates how much a vehicle can resell for at a certain age.
func CalculateResellPrice(originalPrice, age float64) float64 {
if age < 3 {
return 80*originalPrice*0.01
} else if age < 10 {
return 70*originalPrice*0.01
}
return 50*originalPrice*0.01
}
func main() {
needLicense := NeedsLicense("car")
vehicle := ChooseVehicle("Ford Pinto", "Bugatti Veyron")
n := CalculateResellPrice(40000, 3)
fmt.Print(needLicense,"\n",vehicle,"\n",n,"\n")
}