Menu in RAM + correzione stringhe

This commit is contained in:
La Programmatrice Verde
2025-11-27 11:14:06 +01:00
parent 3b998a981d
commit ca81f23ebf
2 changed files with 9 additions and 18 deletions

View File

@@ -36,6 +36,7 @@ public class FatturaScontrini {
static final String ERRORE_DEFAULT = "Errore: opzione non valida."; static final String ERRORE_DEFAULT = "Errore: opzione non valida.";
static final String ERRORE_FILE = "Errore nella lettura del file: "; static final String ERRORE_FILE = "Errore nella lettura del file: ";
static final String ERRORE_MENU_VUOTO = "Errore: il menu è vuoto."; static final String ERRORE_MENU_VUOTO = "Errore: il menu è vuoto.";
static String[][] menu = tabellaNomePrezzo();
static int codiceScontrino = getCodice(0); static int codiceScontrino = getCodice(0);
public static void main(String[] args) { public static void main(String[] args) {
@@ -182,7 +183,7 @@ public class FatturaScontrini {
System.out.print("Scelta: "); System.out.print("Scelta: ");
try { try {
voceSelezionata = sc.nextInt(); voceSelezionata = sc.nextInt() - 1;
sc.nextLine(); sc.nextLine();
if (voceSelezionata < 0 || voceSelezionata >= getFileSize(PATH_MENU)) { if (voceSelezionata < 0 || voceSelezionata >= getFileSize(PATH_MENU)) {
@@ -201,17 +202,8 @@ public class FatturaScontrini {
} }
static void stampaMenu() { static void stampaMenu() {
try (BufferedReader br = new BufferedReader(new FileReader(PATH_MENU))) { for (int i = 0; i < menu[0].length; i++) {
StringTokenizer st; System.out.println((i+1) + ". " + menu[0][i] + ": " + menu[1][i].trim());
String riga = br.readLine();
for (int i = 0; i < getFileSize(PATH_MENU); i++) {
st = new StringTokenizer(riga, ":");
System.out.println(i + ". " + st.nextToken() + ": " + st.nextToken().trim());
riga = br.readLine();
}
} catch (IOException e) {
System.out.println(ERRORE_FILE + e.getMessage());
} }
} }
@@ -293,7 +285,6 @@ public class FatturaScontrini {
static String ordinazioneToString(ArrayList<int[]> ordinazione) { static String ordinazioneToString(ArrayList<int[]> ordinazione) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String[][] menu = tabellaNomePrezzo();
double totale = 0; double totale = 0;
// Larghezze colonne // Larghezze colonne
@@ -369,7 +360,6 @@ public class FatturaScontrini {
static ArrayList<int[]> cancellaOrdine(ArrayList<int[]> ordinazione) { static ArrayList<int[]> cancellaOrdine(ArrayList<int[]> ordinazione) {
int scelta = -1; int scelta = -1;
String[][] menu = tabellaNomePrezzo();
boolean error; boolean error;
do { do {
@@ -489,6 +479,7 @@ public class FatturaScontrini {
break; break;
case 2: case 2:
aggiungiVoceMenu(); aggiungiVoceMenu();
menu = tabellaNomePrezzo();
System.out.println("Piatto aggiunto con successo."); System.out.println("Piatto aggiunto con successo.");
pausa(); pausa();
break; break;
@@ -598,7 +589,7 @@ public class FatturaScontrini {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
System.out.print("Inserire il nome della nuova voce: "); System.out.print("Inserire il nome della nuova voce: ");
nome = sc.nextLine().trim(); nome = sc.nextLine().trim();
System.out.print("Inserire il prezzo della nuova voce: "); System.out.println("Inserire il prezzo della nuova voce");
prezzo = Double.toString(prezzo()); prezzo = Double.toString(prezzo());
if (prezzo.contains(",")) { if (prezzo.contains(",")) {
@@ -623,7 +614,7 @@ public class FatturaScontrini {
do { do {
error = false; error = false;
System.out.print("Inserire il prezzo da acquistare: "); System.out.print("Prezzo: ");
try { try {
prezzo = sc.nextDouble(); prezzo = sc.nextDouble();

View File

@@ -1,4 +1,4 @@
numeroScontrino:257 numeroScontrino:258
numeroFattura:7 numeroFattura:8
username: password username: password
password: username password: username