StampaScontrino
This commit is contained in:
@@ -5,9 +5,14 @@
|
|||||||
package fatturascontrini;
|
package fatturascontrini;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
@@ -81,9 +86,9 @@ public class FatturaScontrini {
|
|||||||
case 2:
|
case 2:
|
||||||
if (ordinazioneEffettuata) {
|
if (ordinazioneEffettuata) {
|
||||||
pagare(ordinazione);
|
pagare(ordinazione);
|
||||||
}
|
} else {
|
||||||
else {
|
System.out.println(
|
||||||
System.out.println("Errore: è necessario effettuare un'ordinazione prima di procedere al pagamento.");
|
"Errore: è necessario effettuare un'ordinazione prima di procedere al pagamento.");
|
||||||
}
|
}
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
@@ -179,7 +184,7 @@ public class FatturaScontrini {
|
|||||||
|
|
||||||
for (int i = 0; i < getMenuSize(); i++) {
|
for (int i = 0; i < getMenuSize(); i++) {
|
||||||
st = new StringTokenizer(riga, ":");
|
st = new StringTokenizer(riga, ":");
|
||||||
System.out.println(i + ". " + st.nextToken() + ": €" + st.nextToken().trim());
|
System.out.println(i + ". " + st.nextToken() + ": " + st.nextToken().trim());
|
||||||
System.out.println("\t" + st.nextToken().trim() + "\n");
|
System.out.println("\t" + st.nextToken().trim() + "\n");
|
||||||
riga = br.readLine();
|
riga = br.readLine();
|
||||||
}
|
}
|
||||||
@@ -260,12 +265,26 @@ public class FatturaScontrini {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void pagare(ArrayList<int[]> ordinazione) {
|
static void pagare(ArrayList<int[]> ordinazione) {
|
||||||
stampaOrdinazione(ordinazione);
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
|
||||||
|
Date now = new Date();
|
||||||
|
String contenutoScontrino;
|
||||||
|
try (BufferedWriter bw = new BufferedWriter(
|
||||||
|
new FileWriter("./src/fatturascontrini/scontrino_" + sdf.format(now) + ".txt"))) {
|
||||||
|
sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
|
||||||
|
contenutoScontrino = "Codice scontrino: " + codiceScontrino++ + "\nData e ora di emissione: "
|
||||||
|
+ sdf.format(now) + "\n\n"
|
||||||
|
+ ordinazioneToString(ordinazione);
|
||||||
|
System.out.println(contenutoScontrino);
|
||||||
|
bw.write(contenutoScontrino);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Errore nella scrittura del file: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String ordinazioneToString(ArrayList<int[]> ordinazione) {
|
static String ordinazioneToString(ArrayList<int[]> ordinazione) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String[][] menu = new String[2][getMenuSize()];
|
String[][] menu = new String[2][getMenuSize()];
|
||||||
|
double totale = 0;
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(PATH_MENU))) {
|
try (BufferedReader br = new BufferedReader(new FileReader(PATH_MENU))) {
|
||||||
String riga = br.readLine();
|
String riga = br.readLine();
|
||||||
|
|
||||||
@@ -275,13 +294,19 @@ public class FatturaScontrini {
|
|||||||
riga = br.readLine();
|
riga = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Nome\tPrezzo\tQuantità");
|
sb.append("Nome\tPrezzo\tQuantità\n");
|
||||||
for (int i = 0; i < ordinazione.size(); i++) {
|
for (int i = 0; i < ordinazione.size(); i++) {
|
||||||
sb.append(menu[0][ordinazione.get(i)[0]] + "\t" + menu[1][ordinazione.get(i)[0]] + "\t"
|
sb.append(menu[0][ordinazione.get(i)[0]])
|
||||||
+ ordinazione.get(i)[1]);
|
.append("\t")
|
||||||
|
.append(menu[1][ordinazione.get(i)[0]])
|
||||||
|
.append("\t")
|
||||||
|
.append(ordinazione.get(i)[1])
|
||||||
|
.append("\n");
|
||||||
|
totale += Double.parseDouble(menu[1][ordinazione.get(i)[0]].replaceFirst(",", ".")) * ordinazione.get(i)[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.append("\nTotale: " + totale);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Errore nella lettura del file: " + e.getMessage());
|
System.out.println("Errore nella lettura del file: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user