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