Skip to content

Commit af795b7

Browse files
committed
Proyectos de ejemplo en Java
0 parents  commit af795b7

File tree

122 files changed

+4803
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+4803
-0
lines changed

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Mobile Tools for Java (J2ME)
2+
.mtj.tmp/
3+
4+
# Package Files #
5+
*.jar
6+
*.war
7+
*.ear
8+
9+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
10+
hs_err_pid*
11+
12+
# Eclipse
13+
.classpath
14+
.project
15+
.settings/
16+
17+
# Intellij
18+
.idea/
19+
*.iml
20+
*.iws
21+
22+
# Mac
23+
.DS_Store
24+
25+
# Maven
26+
log/
27+
target/
28+
29+
# Inclusions
30+
!lib/**
31+
32+
# Compiled Files
33+
*.class
34+
bin/
35+
build/
36+
/bin1/
37+
java/build/**

Agenda/.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### IntelliJ IDEA ###
2+
*.iml
3+
out/
4+
!**/src/main/**/out/
5+
!**/src/test/**/out/
6+
7+
### Eclipse ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
bin/
16+
!**/src/main/**/bin/
17+
!**/src/test/**/bin/
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/nbbuild/
22+
/dist/
23+
/nbdist/
24+
/.nb-gradle/
25+
26+
### VS Code ###
27+
.vscode/
28+
29+
### Mac OS ###
30+
.DS_Store
+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package com.svalero.agenda;
2+
3+
import com.svalero.agenda.modelo.Evento;
4+
import com.svalero.agenda.modelo.Reunion;
5+
import com.svalero.agenda.modelo.Tarea;
6+
import com.svalero.agenda.util.Ficheros;
7+
8+
import java.io.*;
9+
import java.time.LocalDate;
10+
import java.time.format.DateTimeFormatter;
11+
import java.util.ArrayList;
12+
import java.util.Scanner;
13+
14+
import static com.svalero.agenda.util.Ficheros.EVENTOS_DAT;
15+
16+
public class Agenda {
17+
18+
private Scanner teclado;
19+
private ArrayList<Evento> eventos;
20+
21+
public Agenda() {
22+
teclado = new Scanner(System.in);
23+
eventos = new ArrayList<>();
24+
25+
if (new File(EVENTOS_DAT).exists()) {
26+
eventos = Ficheros.cargar(EVENTOS_DAT);
27+
if (eventos == null) {
28+
System.out.println("Se ha producido un error al intentar cargar los datos");
29+
System.exit(1);
30+
}
31+
}
32+
}
33+
34+
public void mostrarMenu() {
35+
do {
36+
System.out.println("AGENDA SAN VALERO");
37+
System.out.println("1. Añadir una tarea");
38+
System.out.println("2. Modificar una tarea");
39+
System.out.println("3. Ver tareas");
40+
System.out.println("4. Buscar una tarea");
41+
System.out.println("5. Eliminar una tarea");
42+
System.out.println("6. Añadir una reunión");
43+
System.out.println("7. Ver reuniones");
44+
System.out.println("8. Ver todos los eventos");
45+
System.out.println("q. Salir");
46+
System.out.print("Opción: ");
47+
String opcion = teclado.nextLine();
48+
49+
switch (opcion) {
50+
case "1":
51+
anadirTarea();
52+
break;
53+
case "2":
54+
modificarTarea();
55+
break;
56+
case "3":
57+
verTareas();
58+
break;
59+
case "4":
60+
// TODO Buscar una tarea por nombre
61+
break;
62+
case "5":
63+
eliminarTarea();
64+
break;
65+
case "6":
66+
anadirReunion();
67+
break;
68+
case "7":
69+
verReuniones();
70+
break;
71+
case "8":
72+
verTodos();
73+
default:
74+
}
75+
76+
if (opcion.equals("q"))
77+
break;
78+
} while (true);
79+
}
80+
81+
private void verTodos() {
82+
for (Evento evento : eventos) {
83+
System.out.println(evento.toString());
84+
}
85+
}
86+
87+
private void anadirTarea() {
88+
System.out.print("Nombre: ");
89+
String nombre = teclado.nextLine();
90+
System.out.print("Descripción: ");
91+
String descripcion = teclado.nextLine();
92+
Tarea tarea = new Tarea(nombre, descripcion);
93+
eventos.add(tarea);
94+
Ficheros.guardar(eventos, EVENTOS_DAT);
95+
}
96+
97+
private void modificarTarea() {
98+
boolean modificada = false;
99+
System.out.print("Nombre?:");
100+
String nombre = teclado.nextLine();
101+
for (Evento evento : eventos) {
102+
if (evento instanceof Tarea tarea) {
103+
if (tarea.getNombre().equals(nombre)) {
104+
System.out.print("Nuevo nombre:");
105+
String nuevoNombre = teclado.nextLine();
106+
System.out.print("Nueva descripción:");
107+
String nuevaDescripcion = teclado.nextLine();
108+
tarea.setNombre(nuevoNombre);
109+
tarea.setDescripcion(nuevaDescripcion);
110+
modificada = true;
111+
break;
112+
}
113+
}
114+
}
115+
if (!modificada) {
116+
System.out.println("No se ha podido encontrar una tarea con ese nombre");
117+
}
118+
}
119+
120+
private void verTareas() {
121+
for (Evento evento: eventos) {
122+
if (evento instanceof Tarea tarea)
123+
System.out.println(tarea.getNombre() + ": " + tarea.getDescripcion());
124+
}
125+
}
126+
127+
private void eliminarTarea() {
128+
System.out.print("Nombre?: ");
129+
String nombre = teclado.nextLine();
130+
// TODO Preguntar al usuario si está seguro
131+
eventos.removeIf(tarea -> tarea.getNombre().equals(nombre));
132+
// TODO Confirmar al usuario que se ha eliminado la tarea
133+
Ficheros.guardar(eventos, EVENTOS_DAT);
134+
}
135+
136+
private void anadirReunion() {
137+
System.out.print("Nombre: ");
138+
String nombre = teclado.nextLine();
139+
System.out.println("Descripción: ");
140+
String descripcion = teclado.nextLine();
141+
System.out.println("Lugar: ");
142+
String lugar = teclado.nextLine();
143+
System.out.println("Fecha (dd-MM-yyyy): ");
144+
String fecha = teclado.nextLine();
145+
LocalDate fechaEvento = LocalDate.parse(fecha, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
146+
System.out.println("Tipo de aviso [pantalla,sms,email]: ");
147+
String tipoAviso = teclado.nextLine();
148+
Reunion.TipoAviso tipoAvisoEvento = Reunion.TipoAviso.valueOf(tipoAviso.toUpperCase());
149+
System.out.println("Tiempo de preaviso (por defecto 30 minutos): ");
150+
String tiempoPreaviso = teclado.nextLine();
151+
int tiempoPreavisoEvento = 30;
152+
if (!tiempoPreaviso.isEmpty())
153+
tiempoPreavisoEvento = Integer.parseInt(tiempoPreaviso);
154+
155+
Reunion reunion = new Reunion(nombre, descripcion, lugar, fechaEvento, tipoAvisoEvento, tiempoPreavisoEvento);
156+
eventos.add(reunion);
157+
Ficheros.guardar(eventos, EVENTOS_DAT);
158+
}
159+
160+
private void verReuniones() {
161+
for (Evento evento : eventos) {
162+
if (evento instanceof Reunion reunion)
163+
System.out.println(reunion.getNombre() + ": " + reunion.getStringFecha() + " | " + reunion.getStringTipoAviso());
164+
}
165+
}
166+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.svalero.agenda;
2+
3+
import com.svalero.agenda.modelo.Contacto;
4+
import com.svalero.agenda.modelo.Persona;
5+
import com.svalero.agenda.modelo.Usuario;
6+
7+
import java.sql.Array;
8+
import java.util.ArrayList;
9+
10+
public class Main {
11+
public static void main(String[] args) {
12+
Agenda agenda = new Agenda();
13+
agenda.mostrarMenu();
14+
15+
Contacto contacto = new Contacto("", "", "", "", "", 10, "");
16+
Usuario usuario = new Usuario("", "", "", "", "", "", "", Usuario.TipoUsuario.USUARIO);
17+
18+
ArrayList<Persona> personas = new ArrayList<>();
19+
personas.add(contacto);
20+
personas.add(usuario);
21+
}
22+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//package com.svalero.agenda;
2+
//
3+
//public class Otro {
4+
// public static void main(String[] args) {
5+
// asdasdasd
6+
// }
7+
//}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.svalero.agenda.modelo;
2+
3+
public class Contacto extends Persona {
4+
5+
private int horaPreferida;
6+
private String notas;
7+
8+
public Contacto(String nombre, String apellidos, String telefono, String direccion, String email, int horaPreferida,
9+
String notas) {
10+
super(nombre, apellidos, telefono, direccion, email);
11+
this.horaPreferida = horaPreferida;
12+
this.notas = notas;
13+
}
14+
15+
public String getNotas() {
16+
return notas;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.svalero.agenda.modelo;
2+
3+
import java.io.Serializable;
4+
5+
public abstract class Evento implements Serializable {
6+
7+
private String nombre;
8+
private String descripcion;
9+
10+
public Evento(String nombre, String descripcion) {
11+
this.nombre = nombre;
12+
this.descripcion = descripcion;
13+
}
14+
15+
public String getNombre() {
16+
return nombre;
17+
}
18+
19+
public void setNombre(String nombre) {
20+
this.nombre = nombre;
21+
}
22+
23+
public String getDescripcion() {
24+
return descripcion;
25+
}
26+
27+
public void setDescripcion(String descripcion) {
28+
this.descripcion = descripcion;
29+
}
30+
31+
public abstract void finalizar();
32+
33+
@Override
34+
public String toString() {
35+
return nombre + ": " + descripcion;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.svalero.agenda.modelo;
2+
3+
public abstract class Persona {
4+
5+
private String nombre;
6+
private String apellidos;
7+
private String telefono;
8+
private String direccion;
9+
private String email;
10+
11+
public Persona(String nombre, String apellidos) {
12+
this.nombre = nombre;
13+
this.apellidos = apellidos;
14+
}
15+
16+
public Persona(String nombre, String apellidos, String telefono, String direccion, String email) {
17+
this.nombre = nombre;
18+
this.apellidos = apellidos;
19+
this.telefono = telefono;
20+
this.direccion = direccion;
21+
this.email = email;
22+
}
23+
24+
public String getNombre() {
25+
return nombre;
26+
}
27+
28+
public void setNombre(String nombre) {
29+
this.nombre = nombre;
30+
}
31+
}

0 commit comments

Comments
 (0)