Problème avec exercice Java
Bonjour, j'ai un exercice en java à faire dont voici l'ennoncé : exercice n°2.1: une classe Counter
Code:
1 2 3 4 5 6 7 8 9 10
| class Counter{
private int count;
public Counter(int val) {...}
public Counter(){...}// compteur initialisé à 0
public int getCount(){...}
public void incrementer(){..}
public void decrementer(){....}
public void afficher(){....};
public void reset(){....};
} |
Travail à réaliser :
1) Donnez le code Java de la classe Counter, avec un petit programme de test pour tester
chacune des méthodes .
Pour le moment, voila ce que j'ai réussit à faire :
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
| public class Counter{
private int count;
public Counter(int val){
count = val;
}
public Counter(){
count = 0;
}//compteur initialise a 0
public int getCount(){
return count;
}
public void incrementer(){
count += val;
}
public void decrementer(){
count -= val;
}
public void afficher(){
system.out.println("le compteur affiche");
}
public void reset(){
count = 0;}
} |
Mais j'ai pas mal d'erreurs et je ne voit pas d'ou elles viennent, voici ces erreurs :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
exo21.java:1: class Counter is public, should be declared in a file named Counter.java
public class Counter{
^
exo21.java:16: cannot find symbol
symbol : variable val
location: class Counter
count += val;
^
exo21.java:16: operator + cannot be applied to int,val
count += val;
^
exo21.java:20: cannot find symbol
symbol : variable val
location: class Counter
count -= val;
^
exo21.java:24: package system does not exist
system.out.println("le compteur affiche");
^
5 errors |
Si quelqu'un pourrai m'aider merci bcp.