-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
137 lines (112 loc) · 4.54 KB
/
main.dart
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
import 'dart:io';
abstract class Customer {
String destination;
String contactPhone;
String contactName;
double Price;
Customer(this.destination, this.contactPhone, this.contactName, this.Price);
void travelBooking() {
print("$contactName's trip to $destination has been booked successfully.");
}
void getTransitToAirport() {
print("$contactName is being transported to the airport.");
}
void additionalRequirements();
}
class IndividualCustomer extends Customer {
String travelInsurancepolicy;
IndividualCustomer(String destination, String contactPhone,
String contactName, double price, this.travelInsurancepolicy)
: super(destination, contactPhone, contactName, price);
@override
void additionalRequirements() {
print("Travel Insurance Policy is : $travelInsurancepolicy");
print("Notifying workplace of $contactName.");
}
}
class FamilyofCustomer extends Customer {
String insuranceCompany;
String familymemberInCanada;
FamilyofCustomer(String destination, String contactPhone, String contactName,
double price, this.insuranceCompany, this.familymemberInCanada)
: super(destination, contactPhone, contactName, price);
@override
void additionalRequirements() {
print("Family Health Coverage provided by: $insuranceCompany");
print("Family member staying in Canada: $familymemberInCanada");
}
}
class GroupofCustomer extends Customer {
String organizingHardware;
String destinationCompany;
GroupofCustomer(String destination, String contactPhone, String contactName,
double price, this.organizingHardware, this.destinationCompany)
: super(destination, contactPhone, contactName, price);
@override
void additionalRequirements() {
print("Organizing Hardware: $organizingHardware");
print("Notifying destination company: $destinationCompany");
}
}
void main() {
List<Customer> customers = [];
bool increaseMore = true;
while (increaseMore) {
print("\nEnter customer type (1. Individual, 2. Family, 3. Group): ");
int customerCategory = int.tryParse(stdin.readLineSync() ?? '') ?? 0;
print("Enter destination: ");
String destination = stdin.readLineSync() ?? '';
print("Enter ContactPhone: ");
String contactPhoneNumber = stdin.readLineSync() ?? '';
print("Enter Contact Name: ");
String contactName = stdin.readLineSync() ?? '';
double price;
while (true) {
print("Enter Price of Trip: ");
price = double.tryParse(stdin.readLineSync() ?? '') ?? -1;
if (price > 0) break;
print("Invalid price. Please enter a positive number.");
}
switch (customerCategory) {
case 1:
print("Enter Travel Insurance Policy Number: ");
String policyNumber = stdin.readLineSync() ?? '';
customers.add(IndividualCustomer(
destination, contactPhoneNumber, contactName, price, policyNumber));
break;
case 2:
print("Enter Family Insurance Company Name: ");
String insuranceCompany = stdin.readLineSync() ?? '';
print("Enter name of Family member(s) staying in Canada: ");
String familyMembers = stdin.readLineSync() ?? '';
customers.add(FamilyofCustomer(destination, contactPhoneNumber,
contactName, price, insuranceCompany, familyMembers));
break;
case 3:
print("Enter Organizing Hardware (whistles, flags, etc.): ");
String hardware = stdin.readLineSync() ?? '';
print("Enter Destination Company Accepting the Group: ");
String destinationCompany = stdin.readLineSync() ?? '';
customers.add(GroupofCustomer(destination, contactPhoneNumber,
contactName, price, hardware, destinationCompany));
break;
default:
print("Invalid selection, please selct from 1,2 or 3");
continue;
}
print("\nWould you like to add another customer? (yes/no): ");
String userSelection = stdin.readLineSync()?.toLowerCase() ?? '';
increaseMore = userSelection == 'yes';
}
print("\nProcessing all customers....\n");
for (var customer in customers) {
customer.travelBooking();
customer.getTransitToAirport();
customer.additionalRequirements();
print("================================");
print("================================");
}
double totalPrice =
customers.fold(0, (sum, customer) => sum + customer.Price);
print("Total cost of all trips: \$${totalPrice.toStringAsFixed(2)}");
}