Mise à jour de mon problème! ;-)
Citation:
Envoyé par
y4n0_Vh
Je comprends merci tout le monde! Je vais essayer de progresser en lisant plus de tutoriel et en regardant des vidéos. Si je peux je ferai un update... Si je réussis à progresser... :ccool:
Voici ma progression après dur labour. :ccool:
Mais, malheureusement je suis encore pris dans une impasse... :?
Lorsque j'exécute mon programme sa l'affiche :
Test 2 Java 146
Réponds aux questions suivantes (un point par bonne réponse).
Tu n'as pas le droit à tes notes n'y à l'aide de ton voisin!
[Question@27d9e895, QuestionAuChoix@5334a2a3, QuestionAuChoix@24a1a602]
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public class QuestionNumerique extends Question{
private double tolerance, b, u;
public QuestionNumerique(String texte, String rep, double tol) {
super(texte,rep);
tolerance = tol;
}
public boolean VerifieReponse(String r) {
getReponseUsager();
Double.parseDouble(getReponse());
double b = 10;
double u = 11;
if(Math.abs(b-u)<= tolerance);
System.out.println("Bonne réponse!");
return true;
}
} |
Code:
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
|
import java.util.Scanner;
public class QuestionnaireTest {
public static void main(String [] args) {
Questionnaire testJava = new Questionnaire("Test 2 Java 146",
"Réponds aux questions suivantes (un point par bonne réponse)." +
"\n Tu n'as pas le droit à tes notes n'y à l'aide de ton voisin!");
Question q = new Question("Qui est l'inventeur du langage Java?","James Gosling");
testJava.ajouteQuestion(q);
q = new QuestionAuChoix ("Où est née l'inventeur du Java?", "2",
"Australie", "Canada", "Angleterre", "États-Unis");
testJava.ajouteQuestion(q);
q = new QuestionAuChoix ("Quel mot réservé désigne une constante", "3",
"static", "private", "final", "switch", "abstract");
testJava.ajouteQuestion(q);
q = new QuestionNumerique("Nombre de classe de l'API Java ?", "2000", 500);
testJava.affiche (new Scanner(System.in));
}
} |
Code:
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
| import java.util.Scanner;
public class Question {
private String texte;
private String reponse;
public Question(String questionText, String rep) {
texte = questionText;
reponse = rep;
}
public String getTexte() {
return texte;
}
Scanner lecteur = new Scanner(System.in);
public String getReponseUsager() {
String reponseUsager = lecteur.nextLine();
return reponseUsager;
}
public boolean verifieReponse(String rep, Object autreObj) {
if (this == autreObj) return true;
if (autreObj == null) return false;
if (getClass() != autreObj.getClass()) return false;
Question autreQuestion = (Question) autreObj;
return texte.equals(autreQuestion.texte) && reponse == autreQuestion.reponse;
}
protected String getReponse() {
return reponse;
}
public void affiche() {
System.out.println(texte + "Votre reponse: " + ((getReponseUsager().equals(reponse) ? "Bonne réponse!" : "Désolé, mauvaise réponse")));
}
} |
Code:
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
| import java.util.ArrayList;
public class QuestionAuChoix extends Question {
private ArrayList<String> choixList;
public QuestionAuChoix(String quest, String rep, String...choix){
super(quest, rep);
choixList = new ArrayList <String>();
}
public QuestionAuChoix(String string, String string2, String string3,
String string4, String string5, String string6) {
this(string6, string6, string6);
}
public QuestionAuChoix(String string, String string2, String string3,
String string4, String string5, String string6, String string7) {
this(string7, string7, string7, string7, string7, string7);
}
public void affiche() {
super.affiche();
choixList.add(getReponse());
System.out.println(choixList);
}
} |
Code:
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
| import java.util.ArrayList;
import java.util.Scanner;
public class Questionnaire {
private ArrayList<Question> questions;
private int nbBonnesRep;
private String titre;
private String instructions;
public Questionnaire(String string, String string2) {
titre = string;
instructions = string2;
questions = new ArrayList<Question>();
nbBonnesRep++;
nbBonnesRep = nbBonnesRep/4;
}
public String getTitre(){
return titre;
}
public String getInstructions() {
return instructions;
}
public void ajouteQuestion(Question q) {
questions.add(q);
}
public ArrayList<Question> getQuestions() {
return questions;
}
public void affiche (Scanner in) {
System.out.println(getTitre() + "\n\n" + getInstructions() + "\n\n" + questions);
}
} |
Merci pour votre temps et encore une fois... tout aide est très appréciées!