Bonjour à tous.
Alors voilà, j'ai passé mon examen en java il y a 2 semaines et j'aimerais réussir à finir ce programme mais je rencontre des problèmes.
Voici l'intitulé de l'examen en PJ exam java.pdf
Et voici mon code
J'ai des soucis sur les fonctions : rechercher continent, getPrixVoyageCatalogue et getDateVOyageCatalogue. J'arrive à faire fonctionner quand je rentre directement la variable dans ma fonction mais quand je dois récupérer, le mois, la destination ou le pays par une saisie clavier, ma fonction ne fonctionne pas. Je n'arrive pas à comprendre pourquoi!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package fr.cnam.exam; import java.util.Scanner; public class Voyage { public static String destination; public static float budget; public static String date; public static String prix; public static String voyageSaisi; public static String mois; public static String paysChoisi; public static String [] catalogueSardaigne; public static String [] catalogueItalie; public static String [] catalogueJapon; public static String [] catalogueChine; public static String [] catalogueGrece; public static final String SEPARATEUR = ":"; public static final String DESTINATION1 = "Italie"; public static final String DESTINATION2 = "Grece"; public static final String DESTINATION3 = "Sardaigne"; public static final String DESTINATION4 = "Chine"; public static final String DESTINATION5 = "Japon"; public static Scanner sc = new Scanner(System.in); public Voyage (String destination, String prix, String date) { Voyage.destination = destination; Voyage.prix = prix; Voyage.date = date; } public static void recupDestination () { Voyage.saisirVoyage(); System.out.println("La destination de votre voyage est " + destination); } public static void informationsVoyage() { System.out.println("Information voyage : destination : " + destination + " budget " + budget); } public static String rechercherContinent(String destination) { String continent = ""; if (destination == DESTINATION1 || destination == DESTINATION2 || destination == DESTINATION3) {continent = "Europe";} if (destination == DESTINATION4 || destination == DESTINATION5) {continent = "Asie";} return "Le voyage que vous avez choisi est sur le continent " + continent; } public static double augmenterBudget (float pourcentage) { System.out.println("*** Augmentation du budget ***"); float pourcentageReel = 1 + (pourcentage /100); budget = budget * pourcentageReel; return budget; } public static String saisirVoyage() { String tab [] = voyageSaisi.split(SEPARATEUR); return tab[0] + SEPARATEUR + tab[1] + SEPARATEUR + tab[2]; } public static void catalogueVoyage() { catalogueChine = new String [5]; catalogueChine [0] = destination = DESTINATION4; catalogueChine [1] = SEPARATEUR; catalogueChine [2] = prix = "1500"; catalogueChine [3] = SEPARATEUR; catalogueChine [4] = date = "15-04-2021"; catalogueGrece = new String [5]; catalogueGrece [0] = destination = DESTINATION2; catalogueGrece [1] = SEPARATEUR; catalogueGrece [2] = prix = "800"; catalogueGrece [3] = SEPARATEUR; catalogueGrece [4] = date = "06-04-2021"; catalogueItalie = new String [5]; catalogueItalie [0] = destination = "Italie"; catalogueItalie [1] = SEPARATEUR; catalogueItalie [2] = prix = "700"; catalogueItalie [3] = SEPARATEUR; catalogueItalie [4] = date = "01-03-2021"; catalogueJapon = new String [5]; catalogueJapon [0] = destination = "Japon"; catalogueJapon [1] = SEPARATEUR; catalogueJapon [2] = prix = "1800"; catalogueJapon [3] = SEPARATEUR; catalogueJapon [4] = date = "21-05-2021"; catalogueSardaigne = new String [5]; catalogueSardaigne [0] = destination = "Sardaigne"; catalogueSardaigne [1] = SEPARATEUR; catalogueSardaigne [2] = prix = "700"; catalogueSardaigne [3] = SEPARATEUR; catalogueSardaigne [4] = date = "06-03-2021"; } public static void afficherCatalogue() { catalogueVoyage(); for (int i = 0; i<catalogueChine.length;i++) { System.out.print(catalogueChine[i]); } System.out.println(""); for (int i = 0; i<catalogueJapon.length;i++) { System.out.print(catalogueJapon[i]); } System.out.println(""); for (int i = 0; i<catalogueGrece.length;i++) { System.out.print(catalogueJapon[i]); } System.out.println(""); for (int i = 0; i<catalogueSardaigne.length;i++) { System.out.print(catalogueSardaigne[i]); } System.out.println(""); for (int i = 0; i<catalogueItalie.length;i++) { System.out.print(catalogueItalie[i]); } System.out.println(""); } public static String getPrixVoyageCatalogue(String destination) { catalogueVoyage(); if (destination == DESTINATION1 || destination == DESTINATION3) prix = "700"; else if (destination == DESTINATION4) prix = "1500"; else if (destination == DESTINATION5) prix = "1800"; else if (destination == DESTINATION2) prix = "800"; return "Le prix de ce voyage est de : " + prix; } public static String [] getDateVoyageCatalogue(String mois) { Voyage.catalogueVoyage(); mois = Voyage.mois; String [] liste = new String [5]; System.out.println("Les voyages disponibles à cette date sont :"); System.out.println("Liste des voyages \n"); if (mois == "3") { for (int i = 0; i<catalogueItalie.length;i++) { System.out.print(catalogueItalie[i]); } System.out.println(""); for (int i = 0; i<catalogueSardaigne.length;i++) { System.out.print(catalogueSardaigne[i]); } System.out.println(""); } else if (mois == "4") { for (int i = 0; i<catalogueChine.length;i++) { System.out.print(catalogueChine[i]); } System.out.println(""); for (int i = 0; i<catalogueGrece.length;i++) { System.out.print(catalogueJapon[i]); } System.out.println(""); } else if (mois == "5") { for (int i = 0; i<catalogueJapon.length;i++) { System.out.print(catalogueJapon[i]); } } else { System.out.println("Nous n'avons pas de voyage à cette date"); } return liste; } public static void main(String[] args) { System.out.println("Quelle destination voulez vous? "); destination = sc.nextLine(); System.out.println("Quel sera votre budget?"); budget = sc.nextFloat(); informationsVoyage(); String continent = rechercherContinent("Japon"); System.out.println(continent); Voyage.augmenterBudget(15); informationsVoyage(); Voyage voyage = new Voyage (destination, prix, date); System.out.println("Entrez votre voyage sous la forme Destination:Prix:Date"); sc.nextLine(); voyageSaisi = sc.nextLine(); Voyage.saisirVoyage(); Voyage.recupDestination(); String moisChoisi; System.out.println("*** Catalogue ***"); Voyage.afficherCatalogue(); System.out.println("Entrez le pays choisi"); destination = sc.nextLine(); prix = Voyage.getPrixVoyageCatalogue("Japon"); System.out.println(prix); System.out.println("Entrez le mois de votre voyage ( 1 = janvier...) :"); moisChoisi = sc.nextLine(); String [] liste = Voyage.getDateVoyageCatalogue(moisChoisi); for (int i = 0; i<liste.length; i++) System.out.println(liste[i]); } }
Quelqu'un pourrait m'aider svp? J'ai demandé une correction à mon prof mais j'ai pas de réponse alors je me tourne vers votre communauté.
Merci de votre lecture.
Laura
Partager