aggiungiNumero
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
package rubricatelefonicafile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
@@ -30,7 +32,7 @@ public class RubricaTelefonicaFile {
|
||||
System.out.println("Scegliere un'opzione:");
|
||||
System.out.println("1. Ricerca numero");
|
||||
System.out.println("2. Aggiunta numero");
|
||||
System.out.println("2. Stampa rubrica");
|
||||
System.out.println("3. Stampa rubrica");
|
||||
System.out.println("0. Esci");
|
||||
System.out.print("Opzione: ");
|
||||
|
||||
@@ -46,7 +48,7 @@ public class RubricaTelefonicaFile {
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
// aggiungiNumero();
|
||||
aggiungiNumero();
|
||||
pausa();
|
||||
break;
|
||||
case 3:
|
||||
@@ -137,4 +139,24 @@ public class RubricaTelefonicaFile {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void aggiungiNumero() {
|
||||
try (FileWriter fw = new FileWriter("./src/rubricatelefonicafile/agenda.txt", true)) {
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
String nome;
|
||||
String telefono;
|
||||
|
||||
System.out.println("Inserire il nome: ");
|
||||
nome = sc.nextLine();
|
||||
|
||||
System.out.println("Inserire il numero di telefono: ");
|
||||
telefono = sc.nextLine();
|
||||
|
||||
bw.write(nome + ";" + telefono + "\n");
|
||||
bw.close();
|
||||
} catch (IOException _) {
|
||||
System.out.println("Errore nella lettura del file.");
|
||||
pausa();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ Mario;02672727
|
||||
Bianca;068382928
|
||||
Francesca;33877778899
|
||||
Valerio;33911112222
|
||||
Verde;1234567890
|
||||
|
||||
Reference in New Issue
Block a user