Skip to content

Commit c21f343

Browse files
committed
Ejercicio #25 completado
1 parent 28f0bc2 commit c21f343

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

Roadmap/25 - LOGS/java/simonguzman.java

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import java.util.ArrayList;
3+
import java.util.InputMismatchException;
24
import java.util.List;
35
import java.util.Scanner;
46
import java.util.concurrent.TimeUnit;
@@ -8,43 +10,54 @@
810

911
public class simonguzman{
1012
public static void main(String[] args) {
11-
//sintaxisLogger();
12-
//exampleLog();
13+
sintaxisLogger();
14+
exampleLog();
1315
advancedLoggingExample();
16+
adittionalExercise();
1417
}
1518
/************************ ejercicio adicional************************/
1619
public static void adittionalExercise(){
20+
List<Task> tasks = new ArrayList<>();
21+
Logger logger = Logger.getLogger(simonguzman.class.getName());
1722
Scanner sc = new Scanner(System.in);
18-
int option;
23+
int option = 0;
1924
do{
2025
menu();
2126
System.out.println("Ingrese una opcion");
22-
option = sc.nextInt();
23-
}while(option != 4);
24-
27+
try {
28+
option = sc.nextInt();
29+
sc.nextLine();
30+
optionsMenu(option, sc, tasks, logger);
31+
} catch (InputMismatchException e) {
32+
System.out.println("ERROR: Entrada invalida, solo ingresar valores numericos");
33+
sc.next();
34+
}
35+
}while(option != 4);
36+
sc.close();
2537
}
2638

27-
public static void optionsMenu(int option){
39+
public static void optionsMenu(int option, Scanner sc, List<Task> tasks, Logger logger){
40+
2841
switch (option) {
2942
case 1:
30-
43+
addTaskMenu(sc, tasks, logger);
3144
break;
3245
case 2:
33-
46+
removeTaskMenu(sc, tasks, logger);
3447
break;
3548
case 3:
36-
49+
listTasks(tasks, logger);
3750
break;
3851
case 4:
3952
outSystem();
4053
break;
4154
default:
42-
throw new AssertionError();
55+
System.out.println("ERROR: Opcion no valida...");
4356
}
4457
}
4558

46-
public static String outSystem(){
47-
return "Saliendo...";
59+
public static void outSystem(){
60+
System.out.println("Saliendo....");
4861
}
4962

5063
public static void menu(){
@@ -55,16 +68,30 @@ public static void menu(){
5568
System.out.println("4. Salir");
5669
}
5770

58-
public void addTask(String name, String description, List<Task> tasks, Logger logger){
71+
public static void addTaskMenu(Scanner sc, List<Task> tasks, Logger logger){
72+
System.out.print("Introduce el nombre de la tarea: ");
73+
String name = sc.next();
74+
System.out.print("Introduce la descripción de la tarea: ");
75+
String description = sc.next();
76+
addTask(name, description, tasks, logger);
77+
}
78+
79+
public static void removeTaskMenu(Scanner sc, List<Task> tasks, Logger logger){
80+
System.out.println("Introduce el nombre de la tarea a eliminar: ");
81+
String name = sc.next();
82+
removeTask(name, tasks, logger);
83+
}
84+
85+
public static void addTask(String name, String description, List<Task> tasks, Logger logger){
5986
long startTime = System.currentTimeMillis();
6087
Task task = new Task(name, description);
6188
tasks.add(task);
62-
logger.info("Tarea añadida: "+task.getName());
89+
logger.info("Tarea añadida: "+task.getName()+ ", Description: "+task.getDescription());
6390
long endTime = System.currentTimeMillis();
6491
logger.info("Tiempo de ejecucion para añadir la tarea: "+(endTime - startTime));
6592
}
6693

67-
public void removeTask(String name, List<Task> tasks, Logger logger){
94+
public static void removeTask(String name, List<Task> tasks, Logger logger){
6895
long startTime = System.currentTimeMillis();
6996
boolean removed = tasks.removeIf(task -> task.getName().equalsIgnoreCase(name));
7097
if(removed){
@@ -105,6 +132,10 @@ public String getName() {
105132
return name;
106133
}
107134

135+
public String getDescription() {
136+
return description;
137+
}
138+
108139
@Override
109140
public String toString() {
110141
return "Tarea: "+ name +", Descripcion: "+description;

0 commit comments

Comments
 (0)