Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Algorithm Help

I need some help creating an algorithm.

Here is the problem:

I have 2 fixed numbers, and then an array of numbers.

The first fixed number represents data for a monthly period. The second fixed number represents a percentage changed for the monthly period from the data this week to the data last week.

The array of numbers is a list of event that occured which caused in the percentage change.

The problem is the array of numbers can include data that had no real effect on the percentage change, so we dont want to include it. So I need an algorithm that can go through the array of numbers and determine what sort of effect it had on the percentage. If it has a large enough effect, print it out, if not, get rid of it. I also want to get rid of data that doesnt agree with the percentage change. For example, if the percentage change is negative, there should be no positive data included in the array of numbers.

Here is an example test case:
Fixed Number 1 = 45,499,632
Fixed Number 2 = -2.4%
Array of Numbers = {-150; 750; -319; 60; -1456; -700; -6420; -700; -350; -147; -290}

So, when we look at the percentage and notice it is negative, we want to get rid of all the positive numbers, which brings our array down to:
Array of Numbers = {-150; -319; -1456; -700; -6420; -700; -350; -147; -290}

Now we want to have a look at the impact of each number of the percentage. Using common sense, I would narrow it down our Array of Numbers to:
Array of Numbers = {-1456; -700; -6420; -700;}

That seems about right, you might even consider removing the -700s as well.