Need help understanding what I just did

So, line 5 starts with the constructor being built. then on line 6 we are setting views for all topics to start at 0. line 12 is returning the string array name topics. line 16 and 17 is setting the getTopTopics as index 0 which gives us the first output of " The top topic is Opinion".

line 20 and 21 is a bit confusing to me. In line 20 we are creating a method that doesn’t return anything and setting a parameter to accept an int with the variable name topicIndex. On line 21 we are taking the views Array and passing the variable topicIndex into it??? I am so confused as to what is going on. Can someone please help me understand this method block, thank you

I’m not well versed in Java but I’d hazard a guess it’s counting how many times a particular topic is viewed (starts at zero, adds 1 every time it’s called). That would make sense considering the final output, perhaps there’s more functionality to add in due course but at present that seems to be it.

how is it counting with that method? how is views[topicIndex] assigned to any called variable

You’ve lost me a bit, views is an array.

So views[0] = views[0] + 1 is equivalent to incrementing the value held at index 0 by 1. Every time you call with a specific index you’re incrementing/counting.

oH! and topicIndex is suppose to hold the values right? The count is stored inside of topicindex on line 20. omg I think I got it, thank you so much

1 Like