This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Comparing integer element data in Arrays

John Karkanis
Greenhorn
Posts: 2
Hello, so I am in a Java class and there is this program that I am struggling to even understand how to do.

There is a Survey Array that takes values from a survey file stored on one's computer (simply known as "survey" with a TXT extension). Each Survey value is composed of 5 elements: "MONTH, DAY, HOUR, MINUTE, ANSWER" and they get added to an Array known simply as SurveyData[] which then somehow goes into an Array known as SurveyResults[] which arranges each value by the answer represented by a number 1-5.

The assignment asks for two programs: one to list the index with the greatest amount of answers corresponding to a number (1-5) and the other to least the index with the least amount. By specific request of the teacher, one is only allowed to use an old-style for loop to do this. Also, it was suggested that one start at index 1 and compare indices backwards (so compare index 1 to index 0, index 2 to index 1, etc.).

David Newton
Author
Rancher
Posts: 12617
What have you tried so far? Have you broken up the problem into easily-understandable "chunks" that describe what you need to do?

John Karkanis
Greenhorn
Posts: 2
I'll try doing it here, then, for the first program:

1. Find a way to segregate the ANSWER data from the SurveyResults Array
2. Count the number of results for each ANSWER in each index denoting a particular answer
3. Create a loop comparing the amount of answers in each index to one another and make this the "greatest amount"
4. If the amount of results in an index is greater than the index before it, make this now the greatest amount
5. Go through the entire Array doing the same thing
6. Print the greatest amount

David Newton
Author
Rancher
Posts: 12617
You left out the "read the file" step, but other than that, on cursory inspection, looks good--I'd probably start by coding up the file read, then start picking apart the lines. What have you gotten for that so far?