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

Michelle Bramlett
Michelle Bramlett
1,253 Points

Would someone look over my code and see if you catch any errors? PEZ Dispenser and Example.java workspace

https://w.trhou.se/8epojlnk15 https://w.trhou.se/afxkcts5e6

I have struggled the last week compiling any new coding in workspace because I keep getting different errors- The errors vary day to day and I have not been able to compile new additions to the code. They look like mirror images to the instructors(to me;), but I must be missing something? Feel like the farther I go the harder this will be to correct. Thanks in advance for any insight!

Errors listed-(today)

Example.java:29: error: cannot find symbol
System.out.printlin("This will never happen");
^
./PezDispenser.java:31: error: cannot find symbol
throw new illegalArgumentException("Too many PEZ!!!");
^

public class Example {

public static void main(String[] args) {
    // Your amazing code goes here...
  System.out.println("We are making a new Pez Dispenser.");
  PezDispenser dispenser = new PezDispenser("Hobbes");
  System.out.printf("The dispenser character is %s\n",
                    dispenser.getCharacterName());
    if (dispenser.isEmpty()) {
      System.out.println("It is currently empty");
    }
  System.out.println("Loading...");
  dispenser.load();
  if (!dispenser.isEmpty()) {
    System.out.println("It is no longer empty");
  }
  while (dispenser.dispense()) {
    System.out.println("Chomp!");
}
  if (dispenser.isEmpty()) {
    System.out.println("Ate all the PEZ!");

} dispenser.load(4); dispenser.load(2); while (dispenser.dispense()){ System.out.println("Chomp!"); } try { dispenser.load(400); System.out.printlin("This will never happen"); } catch (IllegalArgumentException iae) {
System.out.println("Whoa there!"); System.out.printf("The error was: %s\n", iae.getMessage()); } } }

public class PezDispenser { public static final int MAX_PEZ = 12; private String mCharacterName; private int mPezCount;

public PezDispenser(String characterName) { mCharacterName = characterName; mPezCount = 0; }

public boolean dispense() { boolean wasDispensed = false; return wasDispensed; mPezCount--; wasDispensed = true; }

public boolean isEmpty() { return mPezCount == 0; }

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

public void load(int pezAmount) { int newAmount = mPezCount + pezAmount; if (newAmount > MAX_PEZ) { throw new illegalArgumentException("Too many PEZ!!!"); } mPezCount = newAmount; }

public String getCharacterName() { return mCharacterName; } }

Michelle Bramlett
Michelle Bramlett
1,253 Points

I have 2 workspaces listed here, looks a bit chopped sorry!

Jorrell Templeton
Jorrell Templeton
1,563 Points

Example.java:29: error: cannot find symbol System.out.printlin("This will never happen"); ^

You have "printlin", not "println"

1 Answer

./PezDispenser.java:31: error: cannot find symbol throw new illegalArgumentException("Too many PEZ!!!"); ^

it should be: throw new IllegalArgumentException("Too many PEZ!!!");