How do I display average of all positive numbers?

Iam new to Java and I don't know how to display the average of all positive numbers.

This is what I have so far:

import java.util.ArrayList;


public class Numbers {
    private ArrayList<Double> numbers;

    public Numbers() {
        numbers = new ArrayList<Double>();
    }

    /**
     *Add a number to the collection in a client specified position or at the end of the collection
     */
    public void addNumber(double number)
    {
        numbers.add(number);
    }

    /**
     * Display all numbers in the collection
     */
    public void displayNumbers()
    {
        int number = 0;

        while (number < numbers.size()) {
            System.out.println(numbers.get(number));
            number++;
        }
    }

    /**
     * Display all numbers in the collection organized in 2 categories, first the positive numbers, second the
     *negative numbers
     */
    public void displayNumbersInCategories()
    {
        System.out.println("Positive Numbers");

        int number = 0;

        while (number < numbers.size()) {
            if (numbers.get(number) >= 0.0) {
                System.out.println(numbers.get(number));
            }

            number++;
        }

        System.out.println("Negative Numbers");

        for (Double aNumber : numbers) {
            if (aNumber < 0.0) {
                System.out.println(aNumber);
            }
        }
    }

    /**
    * Display the sum of all numbers in the collection
    */
    public void displaySum()
    {
        double sum = 0.0;
        int length = this.numbers.size();
        int counter = 0;

        while (counter < length) {
            sum = sum + this.numbers.get(counter);
            counter++;
        }

        System.out.println(sum);
    }

    /**
    * Display 2 sums: the sum of all positive numbers in the collection and the sum of all negative numbers in
    * the collection
    */
    public void displaySumsInCategories()
    {
        double sum = 0.0;
        int length = this.numbers.size();
        int counter = 0;
        System.out.println("Positive Numbers");

        while (counter < length)
        {
            sum = sum + this.numbers.get(counter);
            counter++;
        }
       

        System.out.println(sum);
        //}
        System.out.println("Negative Numbers");

        for (Double aSum : numbers)
        {
            if (aSum < 0.0)
            {
                System.out.println(aSum);
            }
        }
    }


/**
 * Display the average of all the positive numbers
 */

public void displayPositiveAvg(String)
{
int count = 0;
double sum = 0.0;
while(sum >= count)
{
double value = average;
sum += value;
count++;
}
double average = sum / count;
System.out.println("Average is" + average)
}      
ryanbecker24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:

public void displayPositiveAvg()
{
  double sum = 0.0;
  for(Double number : numbers)
    sum += number;

  System.out.println("Average is" + sum / numbers.size());
}     

Open in new window

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Sorry, I didn't notice the "positive" numbers part, try this...
public void displayPositiveAvg()
{
  double sum = 0.0;
  int count = 0;
  for(Double number : numbers)
  {
    if(number > 0.0)
    {
      sum += number;
      count++;
    }
  }

  System.out.println("Average is " + (sum / count));
}     

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ryanbecker24Author Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.