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 trialCarter Sellers
456 PointsI am having errors in my code and cannot figure out what it is
My Example.java:
public class Example { public static void main (String []args) {
System.out.println("We are making a new Pez Dispenser");
Pez Dispenser = new PezDispenser("Yoda");
System.out.printf("The dispenser is %s %n, dispenser.getCharacterName()
);
String before = dispenser.swapHead("Darth Vader");
System.out.printf("It was %s but Chris switched it to %s %n, before, dispenser.getCharacterName()
);
} }
My PezDispenser.java:
class Pez Dispenser final private String characterName;
public PezDispenser(String characterName) { this.characterName = characterName; }
public String getCharacterName() { return characterName;
}
public String swapHead(String characterName) {
String originalCharacterName = this.characterName; this.characterName = characterName; return originalCharacterName; }
1 Answer
james south
Front End Web Development Techdegree Graduate 33,271 Pointsthe class is PezDispenser but you have Pez Dispenser then no name. later you reference dispenser so you need to add that above where you call the constructor.