Bonjour à tous,

J'essaie de programmer une sorte de calculatrice pour les moyenne avec coef. Il faut qu'elle soit très simple d'utilisation alors j'ai fait en sorte de demander qu'un copié collé des notes (toutes a la fois et avec les coef entre parenthèses) il déduis le nombre de note grace au nombre d'espaces et le programme isole ensuite la partie correspondant à la note et la met dans un tableau, la note est ensuite analysée et sépare le coef de la note (et supprime les parenthèses) et met ensuite la partie note avec le coef correspondant dans un tableau bidimensionnel (si il n'y a pas de parenthèses alors le coef est 1).
Je modifie le tout en "double".
Apres ca le calcul pour faire la moyenne fait appel aux tableaux et la selon les modifications je tombe sur
NullPointerException
ou sur:
Exception in thread "main" java.text.ParseException: Unparseable number: ""
(c'est due a la conversion en double qui s'effectue mal car la dernière note n'est pas incrite dans la derniere place du tableau)

Mettez-y dans votre compilateur vous visualiserai mieux l'erreur:

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
package apprentissage;
 
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Scanner;
 
/**
 *
 * @author Toto
 */
public class Apprentissage {
    private static double[][] cor;
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws ParseException {
        // TODO code application logic here
 
        Scanner sc = new Scanner(System.in);
        double ct = 0, nc = 0, m;
        int i= 0, nn = 0, x = 0;
        System.out.println("rentrez notes:" );
        String notes = sc.nextLine();
        nn = defininbr(notes);
 
       do
        {
            double cor1[][] = séparenote(notes, nn); 
            double n = cor1 [0][x];
            double c = cor1 [1][x];
 
            ct = ct + c;
            nc = nc + n * c;
            i++;
            x++;
        }while(i < nn);
       m = nc / ct;
       System.out.println("votre moyenne est: "+m);
 
 
 
 
 
 
 
 
 
 
}
    public static int defininbr (String notes) { 
        int nn;
       int a = 0, b = 0, c, d;
 
 
do{
 
a = notes.indexOf("   ", a+1);         //les trois espaces correspondent à un site qui sépare les notes par 3 espaces tout simplement.
b++;
}while (a != -1);
 
nn = b;
       return nn; 
    }
 
 
 
 
    public static double[][] séparenote (String notes, int nn) throws ParseException{
 
        int a = 0, b = 0, b2 = 0,  c, d = notes.length(), a2 = 0;
int Indexnote [][] = new int [2][nn];
 
do{
a = notes.indexOf("   ", a+1);      //je cherche l'index de l'espace apres note
b = notes.lastIndexOf(" ", a-1);     // je cherche l'index de l'espace avant la note
 
Indexnote [0][a2] = b+1;
Indexnote [1][b2] = a;
a2++;                              //j'incrémente la valeur de la place dans le tableau
b2++;
 
}while(a2<nn-1);                     //nbr de note
a = notes.length();      
b = notes.lastIndexOf(" ", a-1);
Indexnote [0][a2] = b+1;
Indexnote [1][b2] = a;
 
/*
 * on converti les données en index de la partie note
 */
String partienote [] = new String [nn];  
a2 = 0;
b2 = 0;
a = 0;
String g;
 
do{
partienote [a] = notes.substring(Indexnote[0][a2], Indexnote[1][b2]); 
a2++;
b2++;
System.out.println(""+partienote[a]);
a++;
}while(a<nn);
 
int l = 0;
 
do{
int p = partienote[l].indexOf("(");
double cor1 [][] = new double [2][nn];
                            //à incrementer pour les différentes notes
    NumberFormat monFormatteurDeNombre = NumberFormat.getInstance();
if(p == -1){
 
cor1 [0][l] = monFormatteurDeNombre.parse(partienote[l]).doubleValue();
cor1 [1][l] = 1;
}
else if(p != -1){
 
cor1 [0][l] = monFormatteurDeNombre.parse(partienote[l].substring(0, p)).doubleValue();
String cf = (partienote[l].substring(p+1, partienote[l].length()));
cor1 [1][l] = monFormatteurDeNombre.parse(cf).doubleValue();
}
System.out.println(""+cor1 [0][l]+"("+cor1 [1][l]+")");
l++;
}while(l <=nn);
 
   return cor; 
}
}
Si vous voyez où est l'erreur expliquez la moi parce que la je cale