Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4d47fdaca
|
|||
b815d8945b
|
|||
c0f46727c6
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,4 +23,6 @@
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
|
@@ -1,15 +1,11 @@
|
||||
package agenda;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Manager {
|
||||
String fileName = "contactos.txt";
|
||||
String fichero = "contactos.txt";
|
||||
String carpeta = "datos";
|
||||
ArrayList<Persona> personas;
|
||||
int limite;
|
||||
|
||||
@@ -22,7 +18,7 @@ public class Manager {
|
||||
public void cargar() {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(fileName));
|
||||
in = new BufferedReader(new FileReader(new File(carpeta, fichero)));
|
||||
} catch (Exception e) {
|
||||
// Si no existe el fichero no carga nada
|
||||
System.out.println("La agenda está vacía");
|
||||
@@ -55,7 +51,7 @@ public class Manager {
|
||||
// Guarda siempre ordenado
|
||||
Collections.sort(personas);
|
||||
try {
|
||||
out = new BufferedWriter(new FileWriter(fileName));
|
||||
out = new BufferedWriter(new FileWriter(new File(carpeta, fichero)));
|
||||
for (Persona persona : personas) {
|
||||
out.write(persona.getNombre() + "," + persona.getTelefono());
|
||||
out.newLine();
|
||||
@@ -120,7 +116,7 @@ public class Manager {
|
||||
System.out.println("Nombre - Teléfono");
|
||||
Collections.sort(personas);
|
||||
for (Persona persona : personas) {
|
||||
System.out.println(persona.getNombre() + " " + persona.getTelefono());
|
||||
System.out.println(persona);
|
||||
}
|
||||
System.out.println("------------------------------");
|
||||
}
|
||||
|
@@ -30,6 +30,10 @@ public class Persona implements Comparable {
|
||||
this.telefono = telefono;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return nombre + " " + telefono;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object temp) {
|
||||
Persona persona = (Persona) temp;
|
||||
|
Reference in New Issue
Block a user