It's impossible to tell from the snippet you've provided. There are too many variables that are unknown. But Paul Tomblin is correct: List doesn't have a length() method, but array has a length attribute. Which one describes your list variable?
Compiler issues should almost NEVER be part of a question here. When the compiler gives you a message, it's likely to give you enough information to figure it out with a little research.
When you post a question asking about compilation issues, it says that you weren't willing to invest enough energy or effort to figure it out for yourself.
This works properly. See how your code compares:
package movie;
/**
* ShoppingCart
* User: Michael
* Date: 10/16/10
* Time: 8:07 PM
*/
public class ShoppingCart
{
private Movie[] list;
private int numberOfRecords;
public static void main(String[] args)
{
ShoppingCart cart = new ShoppingCart(args.length);
for (int i = 0; i < args.length; ++i)
{
boolean success = cart.add(args[i], i);
System.out.println("Movie '" + args[i] + (success ? "' was " : " was not ") + "added successfully");
}
boolean success = cart.add("Gladiator", args.length+1);
System.out.println("Movie 'Gladiator'" + (success ? " was " : " was not ") + "added successfully");
System.out.println(cart);
}
public ShoppingCart(int numberOfRecords)
{
this.numberOfRecords = 0;
this.list = new Movie[numberOfRecords];
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
String newline = System.getProperty("line.separator");
for (Movie movie : this.list)
{
builder.append(movie).append(newline);
}
return builder.toString();
}
public boolean add(String title, int productId)
{
if (numberOfRecords == list.length)
{
return false;
}
else
{
list[numberOfRecords] = new Movie(productId, title);
numberOfRecords++;
return true;
}
}
}
class Movie
{
private int id;
private String title;
Movie(int id, String title)
{
this.id = id;
this.title = title;
}
public String getTitle()
{
return title;
}
@Override
public String toString()
{
return "Movie{" +
"id=" + id +
", title='" + title + '\'' +
'}';
}
}