TP08 Polymorphisme
This commit is contained in:
BIN
APL2.1/TP08/Moyenne/Moyenne.class
Normal file
BIN
APL2.1/TP08/Moyenne/Moyenne.class
Normal file
Binary file not shown.
18
APL2.1/TP08/Moyenne/Moyenne.java
Normal file
18
APL2.1/TP08/Moyenne/Moyenne.java
Normal file
@@ -0,0 +1,18 @@
|
||||
public class Moyenne {
|
||||
private int count;
|
||||
private double sum;
|
||||
|
||||
public Moyenne() {
|
||||
count = 0;
|
||||
sum = 0;
|
||||
}
|
||||
|
||||
public void add(Number n) {
|
||||
count++;
|
||||
sum += n.doubleValue();
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return sum / (double)count;
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP08/Moyenne/TestMoyenne.class
Normal file
BIN
APL2.1/TP08/Moyenne/TestMoyenne.class
Normal file
Binary file not shown.
12
APL2.1/TP08/Moyenne/TestMoyenne.java
Normal file
12
APL2.1/TP08/Moyenne/TestMoyenne.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class TestMoyenne {
|
||||
public static void main(String[] args) {
|
||||
Moyenne m = new Moyenne();
|
||||
|
||||
m.add(1);
|
||||
m.add(1.2f);
|
||||
m.add(1.52d);
|
||||
m.add(2);
|
||||
|
||||
System.out.println(m.getAverage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user