-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.dart
71 lines (61 loc) · 1.54 KB
/
test.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
import 'dart:io';
void main() {
Map? map = {};
int choice;
do {
print("1. Add an item");
print("2. Remove an item");
print("3. Alter an item");
print("4. Clear the map");
print("5. Display the map");
print("6. Exit");
print("Enter your choice:");
choice = int.parse(stdin.readLineSync()!);
switch (choice) {
case 1:
print("Enter the key:");
String? key = stdin.readLineSync();
print("Enter the value:");
String? value = stdin.readLineSync();
map[key] = value;
break;
case 2:
print("Enter the key to remove:");
String? key = stdin.readLineSync();
if (map.containsKey(key)) {
map.remove(key);
} else {
print("Key not found!");
}
break;
case 3:
print("Enter the key to alter:");
String? key = stdin.readLineSync();
if (map.containsKey(key)) {
print("Enter the new value:");
String? newValue = stdin.readLineSync();
map[key] = newValue;
} else {
print("Key not found!");
}
break;
case 4:
map.clear();
print("Map cleared!");
break;
case 5:
print("Map contents:");
if (map.isEmpty) {
print("Map is empty");
} else {
map.forEach((key, value) => print("$key: $value"));
}
break;
case 6:
print("Exiting...");
break;
default:
print("Invalid choice!");
}
} while (choice != 6);
}