aggiungiVoceMenu
This commit is contained in:
@@ -446,7 +446,7 @@ public class FatturaScontrini {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// ordinazione = placeOrdinazione(ordinazione);
|
aggiungiVoceMenu();
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@@ -544,6 +544,58 @@ public class FatturaScontrini {
|
|||||||
return failedLoginCount;
|
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() {
|
static void fattura() {
|
||||||
boolean error;
|
boolean error;
|
||||||
String formatoDataInserimento = "dd/MM/yyyy";
|
String formatoDataInserimento = "dd/MM/yyyy";
|
||||||
|
|||||||
Reference in New Issue
Block a user