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 Harnessing the Power of Objects Constants

filibonio hernandez
filibonio hernandez
2,826 Points

Code for exercise is not working any more.

so I am trying to follow along with the teacher with the coding exercise but the code is not working any more I'm hoping someone to be my second eyes and tell me what is going on with it.

Example.java code:

public class Example {

public static void main(String[] args) { // Your amazing code goes here... System.out.println("We are making a new PEZ dispenser"); System.out.printf("FUN FACT: There ar %d PEZ allowed in every dispenser %n", PezDispenser.MAX_PEZ); PezDispenser dispenser = new PezDispenser("Yoda"); System.out.printf("The dispenser is %s %n" , dispenser.getCharacterName() );
System.out.println("filling the dispenser with delicious PEZ..."); dispenser.fill(); }

}

PezDispenser.java:

class PezDispenser { public static final int MAX_PEZ = 12; final private String characterName; private int pezCount;

public PezDispenser(String characterName) { this.characterName = characterName; pezCount = 0; }

public void fill() { pezCount = MAX_PEZ; }

public String getCharacterName() { return characterName; }

public String swapHead(String characterName); String originalCharacterName = this.characterName; this.characterName = characterName; return originalCharacterName; }

Umesh Ravji
Umesh Ravji
42,386 Points

Could you please edit your post and apply the proper markdown to your code, if you don't know how see the markdown cheatsheet :)

1 Answer

Atefe Mosayebi
Atefe Mosayebi
6,868 Points

hey Filibonio, I got the exact same error at the beginning in my exercise! The reason was I forgot to add Type to my static variable declaration, the format is like this:

public static final (type) ALL_NAME_IN_UPPER_CASE = value;