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
| import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
//TODO add custom exception(med only letters).
public class Main {
public static void main(String[] args) throws InterruptedException {
//introduction
System.out.println("Bienvenue");
System.out.println("Préparation");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println("Ready");
Thread.sleep(1000);
System.out.println("===============");
System.out.println("Vous allez maintenant devoir les données relatives à votre stock.");
Thread.sleep(1000);
//Input MED
ArrayList<Medicament> medList = new ArrayList();
Scanner scan = new Scanner(System.in);
boolean medRestart = true;
int iMed = 1;
int iMedList = 0;
while(medRestart == true){
System.out.println("Médicament numéro " + iMed+"...");
System.out.println("Nom du médicament?");
boolean bNomMed = true;
String nomMed = "";
while(bNomMed == true){
try{
nomMed =scan.nextLine();
bNomMed = false;
} catch(InputMismatchException e){
System.out.println("Nom invalide.");
scan.next();
}
}
System.out.println("Prix du médicament?");
int prixMed = -1;
boolean bPrixMed = false;
while(bPrixMed == false){
try{
prixMed = scan.nextInt();
bPrixMed = true;
} catch(InputMismatchException e) {
System.out.println("Le prix doit être un nombre entier.");
scan.next();
}}
medList.add(new Medicament(nomMed, prixMed));
System.out.println("Autre medicament? (O/N)");
scan.nextLine();
char medRestartScan = scan.nextLine().toLowerCase().charAt(0);
while(medRestartScan != 'o' && medRestartScan != 'n'){
System.out.println("Veuillez répondre par 'O' ou 'N'.");
medRestartScan = scan.nextLine().toLowerCase().charAt(0);
}
if(medRestartScan == 'n'){
medRestart = false;
}
iMed++;
iMedList++;
}
//input CLIENTS INTRO
//TODO try catch
ArrayList<Client> cList = new ArrayList();
System.out.println("Préparation");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println(".");
System.out.println("Prêt à recevoir les clients.");
System.out.println("====================");
Thread.sleep(1000);
Client c = new Client();
boolean cRestart = true;
//CLIENT INPUT DONNEES
while(cRestart ==true){
int ic = 1;
int icList = 0;
System.out.println("Client numéro "+ic+"...");
System.out.println("Nom client?");
String nomC = scan.nextLine();
System.out.println("Prénom client?");
String prénomC = scan.nextLine();
System.out.println("Ville du client?");
String villeC = scan.nextLine();
System.out.println("Age client?");
boolean bMismatchAgeC = true;
int ageC = -1;
while(bMismatchAgeC == true){
try{
ageC = scan.nextInt();
bMismatchAgeC = false;
} catch(InputMismatchException e){
System.out.println("L'âge doit être un nombre entier.");
scan.nextLine();
}}
cList.add(new Client(nomC, prénomC, villeC, ageC));
//CLIENT ACHATS
System.out.println("Preparation de la liste pour impression...");
Thread.sleep(1000);
System.out.println(".");
Thread.sleep(1000);
System.out.println(".");
System.out.println("=============");
Thread.sleep(1000);
int iSizeCorrected = (medList.size())-1;
for(int i = 0; i <= iSizeCorrected;i++){
System.out.println(i+" : "+ medList.get(i).getNom());
}
boolean medBoughtStatus = true;
int medBought = -1;
while(medBoughtStatus == true){
while(intervallContains(0, (medList.size()-1), medBought) == false){
System.out.println("Med. acheté? (répondre par l'indice de la liste ci dessus).");
medBought = scan.nextInt();
}
cList.get(icList).cMedList.add(medList.get(medBought));
System.out.println("Autre med. acheté? (O/N)");
scan.nextLine();
String medBoughtStatusBis = scan.nextLine();
char medBoughtStatusBisChar = medBoughtStatusBis.toLowerCase().charAt(0);
while (medBoughtStatusBisChar != 'o' && medBoughtStatusBisChar != 'n')
{
System.out.println("Veuillez répondre par 'O' ou 'N'.");
medBoughtStatusBis = scan.nextLine();
}
if(medBoughtStatusBisChar == 'n'){
medBoughtStatus = false;
}
else if(medBoughtStatusBisChar == 'o'){
medBoughtStatus = true;
}
}
//NEXT CLIENT (?)
ic++;
icList++;
System.out.println("Autre client? (O/N)");
String charC = scan.nextLine().toLowerCase();
boolean bCharC = true;
while(bCharC == true){
if(charC.charAt(0) != 'n' && charC.charAt(0) != 'o'){
System.out.println("Veuillez répondre par 'O' ou 'N'.");
charC = scan.nextLine().toLowerCase();
}
else {
bCharC = false;
}
}
if(charC.charAt(0)=='n')
cRestart = false;
}
}
public static boolean intervallContains(int low, int high, int n) {
return n >= low && n <= high;
}
} |
Partager