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 Exceptions

i am having issues with one of my variables. Please help

PezDispenser.java:

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

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

public void fill() { fill(MAX_PEZ); }

public void fill(int pezAmount) { int newAmount = pezCount + pezAmount; if (newAmount > MAX_PEZ) { throw new IllegalArgumentException("Too many PEZ!!"); } pezCount = newAmount; }

public boolean dispense() { boolean wasDispensed = false; if (!isEmpty()) { pezCount--; wasDispensed = true; } return wasDispenesed; }

public boolean isEmpty() { boolean isActuallyEmpty = pezCount == 0; return isActuallyEmpty; }

public String getCharacterName() { return characterName; }

}

Example.java:

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 are %d Pez in the dispenser %n", PezDispenser.MAX_PEZ); PezDispenser dispenser = new PezDispenser("Yoda"); System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() );

if (dispenser.isEmpty()) {
  System.out.println("Dispenser is empty");
}

System.out.println("Filling the dispenser with delicious pez...");
dispenser.fill();

if (!dispenser.isEmpty()) {
  System.out.println("Dispenser is full");
}

while (dispenser.dispense()) {
  System.out.println("Chomp!");
}
if (dispenser.isEmpty()) {
  System.out.println("Ate all the PEZ ");    
}
dispenser.fill(4);
dispenser.fill(2);
while (dispenser.dispense()) {
  System.out.println("Chomp!!");
}
dispenser.fill(400);
System.out.println("This will never happen");a

}

}

When i run the the output is :

treehouse:~/workspace$ javac Example.java && java Example
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
./PezDispenser.java:26: error: cannot find symbol
return wasDispenesed;
^
symbol: variable wasDispenesed
location: class PezDispenser
1 error

Clement THOLLOT
Clement THOLLOT
1,203 Points

You made a typo. The variable wasDispenesed doesn't exist cause it should be wasDispensed .

1 Answer

gmilan
gmilan
9,287 Points

Clement THOLLOT 14h ago You made a typo. The variable wasDispenesed doesn't exist cause it should be wasDispensed .