-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcabby.go
More file actions
130 lines (122 loc) · 3.95 KB
/
cabby.go
File metadata and controls
130 lines (122 loc) · 3.95 KB
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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"time"
)
func main() {
picUpDropOff()
}
func picUpDropOff() {
var pickUp, dropOff string
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("What is your pick up location?: ")
scanner.Scan()
pickUp = scanner.Text()
var validateLocationConditioner = validateLocation(pickUp)
if validateLocationConditioner == false {
return
}
validateLocation(pickUp)
fmt.Print("Where would you like to go?: ")
scanner.Scan()
dropOff = scanner.Text()
if validateLocationConditioner == false {
return
}
validateLocation(dropOff)
if determineAmount(pickUp, dropOff) == 0 {
return
}
fmt.Println("Your fare cost is ", determineAmount(pickUp, dropOff))
time.Sleep(10 * time.Second)
scanner = bufio.NewScanner(os.Stdin)
fmt.Print("Enter the specified fare: ")
scanner.Scan()
passengerFare := scanner.Text()
newPassengerFare, _ := strconv.Atoi(passengerFare)
Fare := determineAmount(pickUp, dropOff)
for underPaidFare := 0; underPaidFare <= 4; underPaidFare++ {
if newPassengerFare == Fare {
fmt.Println("Thank you for your patronage")
break
} else if newPassengerFare > Fare {
fmt.Println("Here is your change: ", newPassengerFare-Fare)
break
} else if newPassengerFare < Fare {
fmt.Println("The money you paid is not enough, please enter the required amount: ")
scanner.Scan()
passengerFare = scanner.Text()
newPassengerFare, _ = strconv.Atoi(passengerFare)
if underPaidFare == 4 {
fmt.Print("Enter the right amount or you will be reported to the police: ")
scanner.Scan()
passengerFare = scanner.Text()
newPassengerFare, _ = strconv.Atoi(passengerFare)
}
} else {
fmt.Print("Invalid response")
break
}
}
requestTip(Fare)
}
func validateLocation(Locations string) (validLocation bool) {
validLocation = false
if Locations == "Alakahia" || Locations == "Aluu" || Locations == "Choba" || Locations == "Rumuosi" || Locations == "Rumuola" || Locations == "Rumuokoro" || Locations == "Mgbuoba" {
return true
} else if Locations == "" {
fmt.Println("Invalid destination")
return false
} else {
fmt.Print("Sorry our cab service does not operate in that area, bye laters!")
return false
}
return
}
func determineAmount(fromLocation1, toLocation2 string) (Fare int) {
if fromLocation1 == "Alakahia" && toLocation2 == "Choba" ||
fromLocation1 == "Alakahia" && toLocation2 == "Rumuosi" ||
fromLocation1 == "Choba" && toLocation2 == "Alakahia" ||
fromLocation1 == "Choba" && toLocation2 == "Aluu" ||
fromLocation1 == "Aluu" && toLocation2 == "Choba" ||
fromLocation1 == "Choba" && toLocation2 == "Rumuosi" ||
fromLocation1 == "Rumuosi" && toLocation2 == "Choba" ||
fromLocation1 == "Rumuosi" && toLocation2 == "Alakahia" {
return 50
} else if fromLocation1 == "Alakahia" && toLocation2 == "Rumuokoro" ||
fromLocation1 == "Choba" && toLocation2 == "Rumuokoro" ||
fromLocation1 == "Rumuola" && toLocation2 == "Rumuokoro" ||
fromLocation1 == "Rumuosi" && toLocation2 == "Rumuokoro" ||
fromLocation1 == "Rumuokoro" && toLocation2 == "Rumuosi" ||
fromLocation1 == "Rumuokoro" && toLocation2 == "Alakahia" ||
fromLocation1 == "Rumuokoro" && toLocation2 == "Rumuola" ||
fromLocation1 == "Rumuokoro" && toLocation2 == "Mgbuoba" ||
fromLocation1 == "Mgbuoba" && toLocation2 == "Choba" ||
fromLocation1 == "Mgbuoba" && toLocation2 == "Rumuokoro" {
return 100
} else if fromLocation1 == "Rumuola" && toLocation2 == "Choba" ||
fromLocation1 == "Choba" && toLocation2 == "Rumuola" {
return 200
} else {
return
}
return
}
func requestTip(tip int) {
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("What amount is your tip? : ")
scanner.Scan()
tipOffered := scanner.Text()
newTipFromCustomer, _ := strconv.Atoi(tipOffered)
switch newTipFromCustomer >= 0 {
case newTipFromCustomer == 0:
fmt.Println("You are a stingy fool")
case newTipFromCustomer <= tip:
fmt.Println("Thank you")
case newTipFromCustomer >= tip:
fmt.Println("Gracias mucho Mr. Reeves")
}
}