All things are lawful, but not all things are profitable.
Carey Brown wrote:A simple, non-OO way, would be to create a second array to contain the medalCount.
A more OO way would be to create a Country class with fields name and medalCount and have an array of those.
Zach Christian wrote:
Carey Brown wrote:A simple, non-OO way, would be to create a second array to contain the medalCount.
how would I reference the 2 arrays? Say user inputs "Germany" as the country and 1,2,3 for the gold/silver/bronze medals. How would one tie Germany to the number of medals to do a comparison of the other countries?
Carey Brown wrote:
Zach Christian wrote:
Carey Brown wrote:A simple, non-OO way, would be to create a second array to contain the medalCount.
how would I reference the 2 arrays? Say user inputs "Germany" as the country and 1,2,3 for the gold/silver/bronze medals. How would one tie Germany to the number of medals to do a comparison of the other countries?
I don't think a HashMap (per Knute) is appropriate because you'll have to output the countries in the order that they were entered in the event of a tie. An ArrayList would be a better choice.
Tyson Lindner wrote:If you're recording three different medal types you would need at least three different arrays for each medal (int[] bronze, int[] silver, int[] gold, and maybe int[] total). You don't have to loop through your medals in any way while you're looping through your countries.
Parallel arrays can get really messy, if you're capable of using an object oriented approach you should do so.
Zach Christian wrote:I have a Country class, so how would I pass my Scanner into that? Can you show me?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Zach Christian wrote:I have a Country class, so how would I pass my Scanner into that? Can you show me?
Sure:Hopefully you get the idea..,
Another tip: Class names should generally be singular. And if you absolutely must make it plural, then call it 'Countries'. You don't have to forget good spelling just because you're writing a program.
HIH
Winston
Zach Christian wrote:Thanks for the help. Now, if multiple countries are inputted, how do I create multiple objects, say, in a "for loop"? One to data for each country?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here