-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
160 lines (99 loc) · 2.71 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"time"
)
var availableLocations = []string{
"aluu", "choba", "alakahia",
"rumuosi", "rumuokoro", "mgbuoba",
"rumuola",
}
func getPickUpLocationFromUser() string {
text := getAns("\nWhere are you at? ")
for _, v := range availableLocations {
if v == text {
return v
}
}
fmt.Println("\nThis pickup location is not available Yet?")
return getPickUpLocationFromUser()
}
func getDropOffLocationFromUser(pickUp string) string {
text := getAns("\nWhere are you going?")
if text == pickUp {
fmt.Println("\nMy Friend! Choose a different location!!")
return getDropOffLocationFromUser(pickUp)
}
for _, v := range availableLocations {
if v == text {
return v
}
}
fmt.Println("\n We don't go here yet?; choose from available locations!")
return getDropOffLocationFromUser(pickUp)
}
func getAns(msg string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(msg + " ")
text, _ := reader.ReadString('\n')
return strings.ToLower(strings.TrimSpace(text))
}
func getPayment(tFare int, i int) int {
i++
text := getAns("\nEnter Payment tFare? ")
input, err := strconv.Atoi(text)
if err != nil {
fmt.Println("\nType in Valid Numbers!!")
}
if i > 10 {
fmt.Println("\nEnjoy Jail time, Bye!!")
} else if i >= 5 {
fmt.Println(" \nDon't Be Unfortunate! I'm calling the Cops!!")
}
if input == tFare {
fmt.Println("\nAwesome!")
return input
} else if input > tFare {
change := input - tFare
fmt.Printf("\nHere's Your change Sir: ₦%d ", change)
return input
} else if input < tFare {
fmt.Println("\nNice try smarty pants! Pay in full Sir!")
}
return getPayment(tFare, i)
}
func getTip(tFare int) int {
text := getAns("\nPlease tip me Sir (enter tip): ")
tip, err := strconv.Atoi(text)
if err != nil {
fmt.Println("\nType is valid numbers!!")
return getTip(tFare)
}
if tip < 1 {
fmt.Println("\nYou are Stingy fool!!")
} else {
fmt.Println("Gracias mucho!")
}
return tip
}
func main() {
transport := Transport{locations: availableLocations, tFare: 50}
fmt.Printf(" \nAvailable Locations: %s. \n\n", strings.Join(availableLocations, ","))
pickUp := getPickUpLocationFromUser()
transport.setPickUpLocation(pickUp)
dropOff := getDropOffLocationFromUser(transport.pickUp)
transport.setDropOffLocation(dropOff)
transport.setTFare()
fmt.Printf(" \nTP from %s to %s is: ₦%d. \n\n", transport.pickUp, transport.dropOff, transport.tFare)
fmt.Println("Driving...")
time.Sleep(10 * time.Second)
fmt.Printf(" \nWe got here. Pay Up ₦%d.", transport.tFare)
getPayment(transport.tFare, 0)
// fmt.Println(availableLocations[0])
tip := getTip(transport.tFare)
transport.setTip(tip)
}