I’m new to Java so please be gentle…
Consider the following ShoppingList Class:
public class ShoppingList {
...
public ItemPrices[] getSortedPrices(){
//do sorting stuff here etc
return ret.toArray(new ItemPrices[0]);
}
}
And now I have another class called Hello:
public class Hello {
...
private Groceries createGroceries() {
...
pricearray[] = ShoppingList.ItemPrices[] //????
...
}
}
I want to assign the array pricearray I’ve created to equal to ItemPrices array returned in the method.
However I’m not getting what I want, what’s the correct way to doing this?
Unless the method
getSortedPricesis a static method, you need to call it from an instance of theShoppingListclass, so you should create an instance as followsalso, I dont see how
is it supposed to be an array of doubles, or an array of instance of the class
ItemPrices?if its supposed to be an array of doubles, you need to do this:
and the line
PriceList [] pricearray = sList.getSortedPrices()should be
double [] pricearray = sList.getSortedPrices()