This repository was archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddition.java
More file actions
181 lines (136 loc) · 5.91 KB
/
Addition.java
File metadata and controls
181 lines (136 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class Addition {
protected int idCommande;
protected int numCommande;
protected int numTable;
protected double somme = 0;
protected ArrayList<Plat> listeDesPlats;
protected ArrayList<Boisson> listeDesBoissons;
// Obsolète - On crée une addition vierge avec le numéro de la table et une somme nulle
public void initAddition(int numTable, int nbUtilisation) {
this.numTable = numTable;
this.somme = 0;
}
public Addition() {
}
// Obsolète - On crée une addition complète avec le numéro de la table et la somme à payer
public Addition(int numTable, double montant) {
this.numTable = numTable;
this.somme = montant;
}
// Récupère tous les éléments commandés pour ensuite pouvoir calculer le montant total à payer
void calculAddition() {
if (listeDesPlats == null || listeDesPlats.size() == 0) {}
else {
for (int i = 0; i < listeDesPlats.size(); i++) {
somme += listeDesPlats.get(i).getPrix();
}
}
if (listeDesBoissons == null || listeDesBoissons.size() == 0) {}
else {
for (int i = 0; i < listeDesBoissons.size(); i++) {
somme += listeDesBoissons.get(i).getPrix();
}
}
}
// Récupère les éléments commandés de la classe Commande entrée en paramètre, récupère le numéro de la table et le numéro de commande et lance le calcul de l'addition
public void newAddition(Commande maCommande) {
this.idCommande = maCommande.numeroDeCommande;
this.numCommande = idCommande % 100;
this.numTable = (idCommande - numCommande) / 100;
this.listeDesPlats = new ArrayList<Plat> (maCommande.getPlat());
this.listeDesBoissons = new ArrayList<Boisson> (maCommande.getBoisson());
calculAddition();
}
// Prépare une liste textuelle des plats
public String listeDesPlatsTicket() {
String liste = "";
if (this.listeDesPlats == null || listeDesPlats.size() == 0) { return "Aucun plat\n";}
else {
for (int i = 0; i < listeDesPlats.size(); i++) {
liste += listeDesPlats.get(i).getNom() + "- \t" + listeDesPlats.get(i).getPrix() + " e\n";
}
return liste;
}
}
// Prépare une liste textuelle des boissons
public String listeDesBoissonsTicket() {
String liste = "";
if (this.listeDesBoissons == null || listeDesBoissons.size() == 0) { return "Aucune boisson\n";}
else {
for (int i = 0; i < listeDesBoissons.size(); i++) {
liste += listeDesBoissons.get(i).getNom() + "- \t" + listeDesBoissons.get(i).getPrix() + " e\n";
}
return liste;
}
}
// On crée un fichier au nom voulu
// public void enregistrementFichier(int numJour) {
// String cheminDuFichier = "Jour" + numJour + "\\Ticket Table n" + numTable;
// // Créez gn qbdet File pour le fichSgc
// File fichier = new File(cheminDuFichier);
// try {
// // méthode createNewFi1e() pour créer le fichier
// boolean fichierCree = fichier.createNewFile();
// if (fichierCree) {
// System.out.println("Enregistrement du ticket effectué avec succès.");}
// else {
// System.out.println("Erreur, table déjà existante.");
// }
// } catch (IOException e) {
// System.err.println("Une erreur s'est produite lors de l'enregistrement du ticket." + e.getMessage());
// }
// }
// On teste ici son ouverture
// public void testOuverture() {
// Path fichier = Path.of("monFichier.txt");
// boolean estAccessible = Files.isRegularFile(fichier) && Files.isReadable(fichier) && Files.isExecutable(fichier);
// System.out.println(estAccessible);
// }
// A faire ! Permet de stocker un bref récap de la commande pour éditer un ticket final de la journée
// public void editionTicketResume() {
// }
// On enregistre toute la commande dans un fichier texte
public void editionTicket(int numJour) {
// try-with-resources
Charset charset = Charset.forName ("windows-1252");
String nomFichier = "Jour" + numJour + "\\Ticket Table n" + numTable + " Commande n" + numCommande;
String texte = "# Ticket Table n" + numTable + " - Commande n" + numCommande + "\n\n\n";
texte += listeDesPlatsTicket();
texte += listeDesBoissonsTicket();
texte += "\n\nA payer : " + somme;
if (somme >= 2) { texte += " euros"; }
else { texte += " euro"; }
try (BufferedWriter writer = Files.newBufferedWriter(Path.of(nomFichier), charset)) {
writer.write(texte);
}
catch (IOException x) {
System.err.format("IOException : %s%n", x);
}
}
public void testEdition(int numJour, int numTable) {
// try-with-resources
Charset charset = Charset.forName ("windows-1252");
String nomFichier = "Jour" + numJour + "\\Ticket Table n" + numTable + " Commande n" + numCommande;
String texte = "# Ticket Table n" + numTable + " - Commande n" + numCommande + "\n\n\n";
try (BufferedWriter writer = Files.newBufferedWriter(Path.of(nomFichier), charset)) {
writer.write(texte);
}
catch (IOException x) {
System.err.format("IOException : %s%n", x);
}
}
public void ticketFichierDeA_Z(int numJournee) {
}
}