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 trialMonica Dhulipudi
4,075 Points("It was %s but chris switched it to %s",before,dispenser.getCharacterName);
So, we are using two %s here.. %s - Yoda - dispenser.getCharacterName
%s - Darth Vader - before
My Question is HOW did YODA come first@(It was %s) when before is used in the statement and then comes dispenser.getCharacterName...
Is it not supposed to be "It was Darth vader but chris switched it to Yoda"
OUTPUT It was Yoda but chris switched it to Darth Vader
2 Answers
Vidhya Sagar
1,568 PointsThat was because the function swaphead was called in between , which a member, chris from our team acidentally created to change Yoda to Death Vader. But since we do not want anyone to change it we assign the variable to final so that the java compiler gives an error ,whenever a change is being made to the yoda.FInal means you can assign only once Hope this was helpful.
Kayla Flynn
7,652 PointsYes, I missed this too, as it does get unclear here. But if you go back in the video and listen at around 1 min he discusses it. So, Chris made a new method that changed the character head (aka he calls it swapHead) and returns the previous one (aka before, which in Pez.java is labeled as original). Then, get.CharacterName() is getting the input string, aka ("Darth Vader") from Example.java. Hope that helps!