最佳答案
I'm learning Java and I'm having a problem with ArrayList
and Random
.
I have an object called catalogue
which has an array list of objects created from another class called item
.
I need a method in catalogue
which returns all the information on one of the item
objects in the list.
The item
needs to be selected at random.
import java.util.ArrayList;
import java.util.Random;
public class Catalogue
{
private Random randomGenerator = new Random();
private ArrayList<Item> catalogue;
public Catalogue ()
{
catalogue = new ArrayList<Item>();
}
public Item anyItem()
{
int index = randomGenerator.nextInt(catalogue.size());
System.out.println("Managers choice this week" + catalogue.get(index) + "our recommendation to you");
return catalogue.get(index);
}
When I try to compile I get an error pointing at the System.out.println
line saying..
'cannot find symbol variable anyItem'