Skip to content

Commit 3a85424

Browse files
committed
#3 - Dart
1 parent e2e6be0 commit 3a85424

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'dart:io';
2+
3+
void main(List<String> args) {
4+
// Listas
5+
List<int> numeros = [1, 2, 3, 4, 5];
6+
// Sets
7+
Set<String> frutas = {'manzana', 'banana', 'naranja'};
8+
// Mapas
9+
Map<String, int> contactos = {};
10+
int condition = 0;
11+
12+
try{do {
13+
print('''
14+
1. Agregar contacto
15+
2. Eliminar contacto
16+
3. Ver contactos
17+
4. Buscar contacto
18+
5. Salir
19+
''');
20+
21+
String? input = stdin.readLineSync();
22+
if (input != null) {
23+
condition = int.parse(input);
24+
}
25+
26+
switch (condition) {
27+
case 1:
28+
print('Ingrese el nombre del contacto:');
29+
String? nombre = stdin.readLineSync();
30+
print('Ingrese el número del contacto:');
31+
String? numero = stdin.readLineSync();
32+
if (nombre != null && numero != null) {
33+
contactos[nombre] = int.parse(numero);
34+
}
35+
break;
36+
case 2:
37+
print('Ingrese el nombre del contacto a eliminar:');
38+
String? nombreEliminar = stdin.readLineSync();
39+
if (nombreEliminar != null) {
40+
contactos.remove(nombreEliminar);
41+
}
42+
break;
43+
case 3:
44+
print('Contactos:');
45+
contactos.forEach((nombre, numero) {
46+
print('$nombre: $numero');
47+
});
48+
break;
49+
case 4:
50+
print('Ingrese el nombre del contacto a buscar:');
51+
String? nombreBuscar = stdin.readLineSync();
52+
if (nombreBuscar != null && contactos.containsKey(nombreBuscar)) {
53+
print('$nombreBuscar: ${contactos[nombreBuscar]}');
54+
} else {
55+
print('Contacto no encontrado');
56+
}
57+
break;
58+
case 5:
59+
print('Saliendo...');
60+
break;
61+
default:
62+
print('Opción no válida');
63+
}
64+
} while (condition != 5);}
65+
catch(e){
66+
print('Error: $e');
67+
}
68+
}

0 commit comments

Comments
 (0)