• Post Reply Bookmark Topic Watch Topic
  • New Topic

Any tips would be appreciated  RSS feed

 
Bob Turner
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a program that prints 6 names and asks the user to input 6 scores for the names. I need to print the highest score with the name associated to it on the same line. The same goes for the lowest. I am having trouble adding the code for this. Any help would be appreciated
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data structure that associates one value with another is call a Map.  In most cases you can use the HashMap implementation.  you should be able to click on HashMap to get the documentation on it.

How would you use this data structure in your program?
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two arrays that you're trying to keep in sync
Notice that numbers is one element shorter than names.

This is error prone and also a non-OO approach. You'd be better off creating a simple class (e.g. "Person") and having a single array of that class. A Person would have two fields: name and number.

When you go to find the min and max numbers you'll want to save the Person associated with the min and/or max numbers.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!