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 Refactoring

"Bummer! Did you uncomment the line in Example.java? The output from System.out does not show the 1 Yoda PEZ dispenser.

I did remove the comments in java the cart.addItem(dispenser); and yet I kept receiving errors despite I did correctly in Shopping cart.java the following method signature

public void addItem(Product item) { int quantity=1; System.out.printf("%n %d %s ", quantity, item.getName()); }

What is going on Treehose please help

6 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Hey Nino,

Without seeing your code, it's really hard to troubleshoot, but from what you wrote for the instructions, and what you wrote that you did, it seems that you may have deleted the commented lines instead of just UN-commenting them out. Those lines need to be there, and be an active part of the code.



I had the same error. What you probably did is change the original addItem method. What they want you to do is leave the original addItem method alone and just create another method named addItem which holds the changes that they are asking for in the challenge prompt. So you should have two addItem method but 1 accepts 2 parameters (item and quantity) and the other just takes 1 parameter (item). Hope it helps.

I highly appreciate Thank you Mr.Jeremy Smith and Mr.Jason Anders and Mr.Jason Anders for the help both suggestions work well

Łukasz Łyś
Łukasz Łyś
916 Points

Hey, I'm having the same problem, all i did in Example.java was remove // next to cart.addItem(dispenser);

so it went from:




and that's it

In ShoppingCart.java my method looks like this

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

even when I check the preview it says:

Adding 5 of Cherry PEZ refill (12 pieces) to the cart.

1 Yoda PEZ dispenser added to the cart.

How is it possible the preview shows the message but I still get "Bummer! Did you uncomment the line in Example.java? The output from System.out does not show the 1 Yoda PEZ dispenser." error?

Yes its true uncomment example.java (the one they want) then create two kinds of method for public void addItem() the 1st one accepts 2 parameters quantity and product. The other public void addItem() accepts only product (the one you did) but as far as the System.out.printf is concerned it should have %d (not "1") to show the value of int quantity=1(you must declare this variable with fix value equals 1)