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 Build a JavaFX Application Build a Pomodoro App Enums

JavaFX Enum challenge 2/2

Having trouble coming up with the correct solution to this challenge. I am not sure what the error message is telling me:

./com/example/model/Brand.java:4: error: constructor Brand in enum Brand cannot be applied to given types; JVC, ^ required: Brand found: no arguments reason: actual and formal argument lists differ in length

I tried to providing arguments to the enum values (eg. SONY(Sony), COBY(Coby)...) whic generate different types of errors. I've looked at other examples in the Java documentation and Stack Overflow as well as other sites and what I am doing seems like it should work; so, I am thinking that it is something minor. If anyone could help and point me in the right direction; it would be greatly appreciative. Thanks.

com/example/model/Brand.java
package com.example.model;

public enum Brand {
  JVC,
  SONY,
  COBY,
  APPLE;

    private Brand displayName;

    Brand(Brand Sony) {
        displayName = Sony;
    }

    public Brand getDisplayName() {
        return displayName;
    }
}

2 Answers

Emil Rais
Emil Rais
26,873 Points
public enum Brand {
  // This is where the different instances of the Brand enumeration are declared
  JVC,
  SONY,
  COBY,
 APPLE;

  // This is the enum constructor
  Brand(Brand Sony) {
  }
}

The enum constructor should match the declarations. Right now you pass nothing to the enums when you create them, but the constructor expects to receive a Brand. This is how you pass your information along to the enum.

public enum Brand {
  JVC("JVC"),
  SONY("Sony"),
  COBY("Coby"),
  APPLE("Apple");

  Brand(String name) {
  }
}

Notice how the string argument is passed to the enumerations and how the constructor has been changed to accept a String. I also renamed the constructor parameter to better align with what it was going to contain. The rest you seem to have all figured out. Happy coding.

Thank you Emil; I haven't had a chance to try it yet but you have cleared up my confusion. Thanks again.