0

I can't seem to find out why it doesnt work with average or smallest but largest and sum does work.

```
//constructor
public class DataSet
{
private int sum = 0;
private int count = 0;
private int Smallest;
private int largest;
public DataSet()
{
}
public void addValue(int a)
{
sum = sum + a;
count++;
Smallest = Math.min(Smallest,a);
largest = Math.max(largest, a);
}
public int getSum()
{
return sum;
}
double getAverage()
{
double avg;
avg = sum / count;
return avg;
}
public int getSmallest()
{
return Math.min(Smallest, largest);
}
public int getLargest()
{
return Math.max(Smallest,largest);
}
}
//tester
import java.util.Scanner;
class DataSetTester
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
System.out.println("Enter first number");
int w = in.nextInt();
System.out.println("Enter second number");
int x = in.nextInt();
System.out.println("Enter third number");
int y = in.nextInt();
System.out.println("Enter fourth number");
int z = in.nextInt();
DataSet set1 = new DataSet();
set1.addValue(w);
set1.addValue(x);
set1.addValue(y);
set1.addValue(z);
System.out.println("The sum is:" + set1.getSum());
System.out.println("The avgerage is:" + set1.getAverage());
System.out.println("The smallest is:" + set1.getSmallest());
System.out.println("The largest is:" + set1.getLargest());
System.exit(0);
}
}
```

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting