Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Delivering the MVP Defaulting Parameters

What is the problem with this code?

public void addItem(Product item) { System.out.printf("%s",item.getName()); } I am geting this message.
Did you uncomment the line in Example.java? The output from System.out does not show the 1 Yoda PEZ dispenser

3 Answers

Make sure you uncomment

cart.addItem(dispenser);

from Example.java

I have uncomment that line

 public void addItem(Product item) {
    System.out.printf("Adding %d of %s to the cart.%n", 1, item.getName());
  }

The only way this differs is that I am also logging a 1 because this assumes that only 1 is being added when addItem is called.

jason phillips I had the same problem. Do you know why this would be invalid? Or would it have just been bad practice?

 public void addItem(Product item) {
    System.out.printf("Added 1 %s to the cart.%n", item.getName());
  }

Thank you it worked