aspose file tools*
The moose likes Beginning Java and the fly likes Comparing integer element data in Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing integer element data in Arrays" Watch "Comparing integer element data in Arrays" New topic
Author

Comparing integer element data in Arrays

John Karkanis
Greenhorn

Joined: Apr 03, 2010
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

Joined: Sep 29, 2008
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

Joined: Apr 03, 2010
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

Joined: Sep 29, 2008
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing integer element data in Arrays