Bonjour a vous tous
j'ai besoin de votre aide pour un erreur de declaration API DOM
pourriez vous verifier ma déclaration en rouge car je ne sais pas
ou est l'erreur
merci de votre temps
Voci mon code
voici input attendu lorsque je tape la ligne de commande suivante
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 public class calculatrice2 { public static void main(String[] args) { int num1 = Integer.parseInt(args[0]); String num2 = (args[1]); int num3 = Integer.parseInt(args[2]); int numsum = (num1+num3); int numsub = (num1-num3); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); Document doc = parser.parse(); Element math = doc.createElement("math"); math.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"); doc.appendChild(math); Element mrow = doc.createElement("mrow"); Element mn1 = doc.createElement("mn"); mn1.appendChild(doc.createTextNode(args[0])); Element mo1 = doc.createElement("mo"); mo1.appendChild(doc.createTextNode(args[1])); Element mn2 = doc.createElement("mn"); mn2.appendChild(doc.createTextNode(args[2])); Element mo2 = doc.createElement("mo"); mo2.appendChild(doc.createTextNode("=")); Element mn3 = doc.createElement("mn"); mn2.appendChild(doc.createTextNode("results")); Element mrow1 = doc.createElement("mrow"); Element mtext = doc.createElement("mtext"); mtext.appendChild(doc.createTextNode("vrai")); mrow.appendChild(mn1); mrow.appendChild(mo1); mrow.appendChild(mn2); mrow.appendChild(mo2); mrow.appendChild(mn3); mrow.appendChild(mrow1); mrow1.appendChild(mtext); math.appendChild(mrow); switch (args[2]) { //Addition case "+": Element mn6 = doc.createElement ( "mn"); mn6.appendChild(doc.createTextNode(Integer.toString(numsum))); //Soustraction case "-": Element mn7 = doc.createElement ( "mn"); mn7.appendChild(doc.createTextNode(Integer.toString(numsub))); //Comparaisons case "<": if(Integer.parseInt(args[1])<Integer.parseInt(args[3])) //Result=="vrai"; {Element mtext1 = doc.createElement ("mtext"); mtext.appendChild(doc.createTextNode("vrai"));} else //Result=="faux"; {Element mtext2 = doc.createElement ("mtext"); mtext.appendChild(doc.createTextNode("faux"));} case ">": if(Integer.parseInt(args[1])>Integer.parseInt(args[3])) //Result=="vrai"; {Element mtext3 = doc.createElement ("mtext"); mtext.appendChild(doc.createTextNode("vrai"));} else //Result=="faux"; {Element mtext4 = doc.createElement ("mtext"); mtext.appendChild(doc.createTextNode("faux"));} } TransformerFactory tfact = TransformerFactory.newInstance(); Transformer transformer = tfact.newTransformer(); transformer.setOutputProperty("encoding", "ISO-8859-1"); DOMSource source = new DOMSource(doc); FileWriter fw = new FileWriter(args[0]); StreamResult result = new StreamResult(System.out); transformer.transform(source, result);} }
java calculatrice2 2-1
et voici le resultat attendu lorsque je tape la ligne de commande
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="ISO-8859-1"?> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mn>2</mn> <mo>-</mo> <mn>1</mn> <mo>=</mo> <mn>1.0</mn> </mrow> </math>
java calculatrice2 1.5 "<" 2
je pense que je suis encore loin de la solution!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="ISO-8859-1"?> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mn>1.5</mn> <mo><</mo> <mn>2</mn> <mo>=</mo> <mrow><mtext>vrai</mtext></mrow> </mrow> </math>
Partager