Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions solutions/go/vehicle-purchase/1/vehicle_purchase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package purchase

import (
"fmt"
"strings"
)

// 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 {
if kind == "car" || kind == "truck" {
return true
} else {
return false
}
}

// ChooseVehicle recommends a vehicle for selection. It always recommends the vehicle that comes first in lexicographical order.
func ChooseVehicle(option1, option2 string) string {
if strings.Compare(option1, option2) <= 0 {
return option1 + " is clearly the better choice."
}

return option2 + " 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 {
resellPrice := originalPrice * 0.8
fmt.Println(resellPrice)
return resellPrice
} else if age >= 10 {
resellPrice := originalPrice * 0.5
fmt.Println(resellPrice)
return resellPrice
} else {
resellPrice := originalPrice * 0.7
return resellPrice
}
}