Object can't access all the data from another object, but only what I've specified. How to fix?
I'd use something like this ... you need a 2nd variable to capture the Stock, and a method to get the Stocks (getStocks()):
public void FindMostFrequency()
{
double temp = 0;
Stock mostFrequentStock = null;
for (Stock aStock : getStocks()) {
var frequency = aStock.frequency
if (temp < frequency) {
temp = frequency;
mostFrequentStock = aStock
}
}
System.out.println("The stock with most frequency is: " + mostFrequentStock);
}
It would also be better to access the variable using a getter instead of directly, ie getFrequency()