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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
public class GestionVol {
static BufferedWriter tEcrire;
static BufferedReader tLire;
final static public int MAX_PLACES = 340 ;
static ArrayList<Vol> tabvol= new ArrayList<Vol>();
public static int menu() {
int choix;
String contenu="\n***** GESTION DES VOLS *****";
contenu+="\n1-Liste des vols ";
contenu+="\n2-Ajout d'un vol ";
contenu+="\n3-Retrait d'un vol ";
contenu+="\n4-Modification de la date du départ";
contenu+="\n5-Réservation d'un vol";
contenu+="\n6-Terminer";
contenu+="\n\nFaite votre choix : ";
choix=Integer.parseInt(JOptionPane.showInputDialog(null, contenu,
"CIE AIR RELAXE", JOptionPane.PLAIN_MESSAGE));
return choix;
}
public static void valideDate () {
int mois = 0;
int an = 0;
int jour = 0;
System.out.println(Date.validerDate(jour, mois, an, null));
}
public static void chargerVols() throws IOException
{
String ligne;
String[] tab = new String [6];
BufferedReader fichier = new BufferedReader(new FileReader("src/Cie_Air_Relax.txt"));
while((ligne = fichier.readLine())!= null)
{
tab = ligne.split(":");//tab[0] contient le Numero du vol, tab[1] destination de vol,
//tab[2] contient le jour,tab[3] contient le mois, tab[4]contient l'annee
// tab[5] contient nombres Total des reservations
Date dateDepart=new Date(Integer.parseInt(tab[2]), Integer.parseInt(tab[3]), Integer.parseInt(tab[4]));
tabvol.add(new Vol(Integer.parseInt(tab[0]), tab[1], dateDepart,Integer.parseInt(tab[5])));
}
fichier.close();
}
public static void sauvegarderVol() throws IOException {
tEcrire = new BufferedWriter(new FileWriter("src/Cie_Air_Relax.txt"));
String ligneEcrire="";
for (Vol unVol : tabvol) {
ligneEcrire=unVol.getNumeroVol()+":"+unVol.getDestVol()+":"+unVol.getdateDepart().getJour()+":"+unVol.getdateDepart().getMois()+":"+unVol.getdateDepart().getAnnee()+":"+
+unVol.getNbTotalReservation();
tEcrire.write(ligneEcrire);
tEcrire.newLine();//Passer à la ligne suivante dans le fichier
}
tEcrire.close();
}
public static void Listevol() throws IOException
{
JTextArea sortie = new JTextArea(15,35);
sortie.setFont(new Font("Verdana", + Font.BOLD, 15));
sortie.setLineWrap (true);
sortie.setWrapStyleWord (true);
sortie.append("\t "+"LISTE DES VOLS"+"\n\n");
sortie.append("Numéro Destination Date depart Réservation\n");
for (Vol unVol : tabvol)
{
sortie.append(unVol.toString()+ "\n");
}
JOptionPane.showMessageDialog(null, sortie, "Cie Air Relax", JOptionPane.PLAIN_MESSAGE);
}
public static int rechercherVol(int no, ArrayList<Vol> tableauvols)
{
for (int i=0;i<tableauvols.size();i++){
if(tableauvols.get(i).getNumeroVol()==no)
return i;
}
return -1;
}
public static void insererVol()throws IOException
{
int Nvol = Integer.parseInt(JOptionPane.showInputDialog("Numéro du vol "));
if (rechercherVol(Nvol, tabvol) != -1) {
JOptionPane.showMessageDialog(null, "Ce vol existe deja, veuillez choisir un autre vol svp " );
}
else {
String DestVol=(JOptionPane.showInputDialog(null,"Distination du vol ","AJOUT D'UNE DESTINATION"
, JOptionPane.PLAIN_MESSAGE));
Date d1 = new Date (Integer.parseInt(JOptionPane.showInputDialog("jour de départ ")),
Integer.parseInt(JOptionPane.showInputDialog("mois de départ")) ,
Integer.parseInt(JOptionPane.showInputDialog("Année de départ ")));
tabvol.add(new Vol(Nvol, DestVol, d1 , 0));
}
}
public static void retrait ()throws IOException
{
String message= " ";
int retVol = Integer.parseInt(JOptionPane.showInputDialog("Numéro du vol "));
int posi = rechercherVol(retVol, tabvol);
if (posi != -1) {
message = "numVol= "+tabvol.get(posi).getNumeroVol()+"\n"+"Destination= "+ tabvol.get(posi).getDestVol()
+"\n"+"Date de départ="+ tabvol.get(posi).getdateDepart()+"\n"+"Nombre de réservation="
+tabvol.get(posi).getNbTotalReservation()+"\n"+"Voulez-vous vraiment retirer ce vol (O/N)?";
int reponse;
reponse=JOptionPane.showConfirmDialog(null,message, "Retrait d'un vol",JOptionPane.YES_NO_OPTION);
if(reponse==JOptionPane.YES_OPTION){
tabvol.remove(tabvol.get(posi));
}
else {
JOptionPane.showMessageDialog(null,"le vol n'est pas dans notre liste, veuillez choisir un autre "
+ tabvol.get(posi).getNumeroVol(),"Retrait d'un vol",JOptionPane.YES_NO_OPTION );
}
}
}
public static void modification ( )throws IOException {
int modVol = Integer.parseInt(JOptionPane.showInputDialog("Numéro du vol "));
int posi = rechercherVol(modVol, tabvol);
if (posi != -1) {
String message = "numVol= "+tabvol.get(posi).getNumeroVol()+"\n"+"Destination= "+ tabvol.get(posi).getDestVol()
+"\n"+"Date de départ="+ tabvol.get(posi).getdateDepart()+"\n"+"Nombre de réservation="
+tabvol.get(posi).getNbTotalReservation()+"\n"+"Donnez la nouvelle date ";
String reponse;
reponse=JOptionPane.showInputDialog(null,message, "Modifier date de départ",JOptionPane.PLAIN_MESSAGE);
StringTokenizer st=new StringTokenizer(reponse,"/");
int jour=Integer.parseInt(st.nextToken());
int mois=Integer.parseInt(st.nextToken());
int an=Integer.parseInt(st.nextToken());
tabvol.get(posi).setDateDepart(new Date(jour,mois,an));
}
else {
JOptionPane.showMessageDialog(null,"vol introuvable , veuillez choisir un autre "
,"Modifier date de départ",JOptionPane.YES_NO_OPTION);
}
}
public static void reservation ()throws IOException {
int resVol = Integer.parseInt(JOptionPane.showInputDialog("Numéro du vol "));
int posi = rechercherVol(resVol, tabvol);
if (posi != -1) {
String message = "numVol= "+tabvol.get(posi).getNumeroVol()+"\n"+"Destination= "+ tabvol.get(posi).getDestVol()
+"\n"+"Date de départ="+ tabvol.get(posi).getdateDepart()+"\n"+"Nombre de réservation="
+tabvol.get(posi).getNbTotalReservation()+"\n"+"Donnez le nombre réservation ?";
int nbRes;
nbRes=Integer.parseInt(JOptionPane.showInputDialog(null,message,
" RÉSERVATION D'UN VOL",JOptionPane.PLAIN_MESSAGE));
if (nbRes + tabvol.get(posi).getNbTotalReservation()<= MAX_PLACES) {
tabvol.get(posi).setNbTotalReservation(nbRes+tabvol.get(posi).getNbTotalReservation());
}
}else
{
JOptionPane.showMessageDialog(null,"Nombre de places insuffisent dans l'avion pour le vol "
+ tabvol.get(posi).getNumeroVol(),"Reserver vol",JOptionPane.YES_NO_OPTION );
}
}
public static void main(String[] args) throws IOException {
chargerVols();
int choixUtilisateur;
do{
choixUtilisateur=menu();
switch(choixUtilisateur)
{
case 1 :
Listevol();
break;
case 2 :
insererVol();
break;
case 3 :
retrait();
break;
case 4 :
modification( );
break;
case 5 :
reservation();
break;
case 6 :
sauvegarderVol();
JOptionPane.showMessageDialog(null, "\n AU REVOIR ET À BIENTÔT ");
break;
default:
JOptionPane.showMessageDialog(null, "\nVotre choix est invalide",null, JOptionPane.YES_NO_OPTION);
}
}
while(choixUtilisateur!=6);
}
} |
Partager