DEV/DEV2.1/TP4/Moyenne.java

55 lines
579 B
Java
Raw Permalink Normal View History

2023-03-27 11:21:24 +02:00
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) {
2023-04-26 11:00:04 +02:00
Moyenne test = new Moyenne();
test.add(10);
test.add(20.0);
test.add();
2023-03-27 11:21:24 +02:00
}
}