55 lines
579 B
Java
55 lines
579 B
Java
public class Moyenne {
|
|
float value = 0;
|
|
int nbVal = 0;
|
|
public void add(int x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public void add(short x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public void add(long x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public void add(double x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public void add(byte x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public void add(float x)
|
|
{
|
|
value+=x;
|
|
nbVal++;
|
|
}
|
|
|
|
public float getAverage()
|
|
{
|
|
return value/nbVal ;
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
Moyenne test = new Moyenne();
|
|
test.add(10);
|
|
test.add(20.0);
|
|
test.add();
|
|
|
|
|
|
|
|
}
|
|
} |