aggiungiVoceMenu

This commit is contained in:
La Programmatrice Verde
2025-11-25 18:33:16 +01:00
parent f9d6859b51
commit bb7a54de1f

View File

@@ -446,7 +446,7 @@ public class FatturaScontrini {
pausa();
break;
case 2:
// ordinazione = placeOrdinazione(ordinazione);
aggiungiVoceMenu();
pausa();
break;
case 3:
@@ -544,6 +544,58 @@ public class FatturaScontrini {
return failedLoginCount;
}
static void aggiungiVoceMenu() {
String nome;
String prezzo;
StringBuilder sb = new StringBuilder();
System.out.print("Inserire il nome della nuova voce: ");
nome = sc.nextLine().trim();
System.out.print("Inserire il prezzo della nuova voce: ");
prezzo = Double.toString(prezzo());
if (prezzo.contains(",")) {
prezzo = prezzo.replace(",", ".");
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(PATH_MENU, true))) {
sb.append(nome);
sb.append(": ");
sb.append(prezzo);
sb.append("\n");
bw.write(sb.toString());
} catch (IOException e) {
System.out.println(ERRORE_FILE + e.getMessage());
}
}
static double prezzo() {
boolean error;
double ritorno = -1;
do {
error = false;
System.out.print("Inserire il prezzo da acquistare: ");
try {
ritorno = sc.nextDouble();
sc.nextLine();
if (ritorno <= 0) {
System.out.println("Errore: non è possibile impostare un prezzo minore di zero.");
pausa();
error = true;
}
} catch (InputMismatchException _) {
System.out.println(ERRORE_DEFAULT);
pausa();
error = true;
}
} while (error);
return ritorno;
}
static void fattura() {
boolean error;
String formatoDataInserimento = "dd/MM/yyyy";