TP07
This commit is contained in:
28
DEV2.1/TP07/Moyenne.java
Normal file
28
DEV2.1/TP07/Moyenne.java
Normal file
@@ -0,0 +1,28 @@
|
||||
public class Moyenne {
|
||||
private double moyenne;
|
||||
private int compteur;
|
||||
|
||||
public Moyenne() {
|
||||
this.moyenne = 0;
|
||||
this.compteur = 0;
|
||||
}
|
||||
|
||||
public double add(Number n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n.doubleValue();
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return this.moyenne / this.compteur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Moyenne m = new Moyenne();
|
||||
m.add(2);
|
||||
m.add(5.4);
|
||||
m.add(547L);
|
||||
System.out.println(m.getAverage());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user