Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Comparing integer element data in Arrays

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.).

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic