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

Sebastian Portocarrero Leon
Sebastian Portocarrero Leon
3,871 Points

I need help with the constuctor

I have this error: Expected enum to contain value 'Sony' but didnt not. Please add it

i dont know what is wrong with my code can somebody help me?

package com.example.model;

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

private String nName

Brand(String Sony) {
    nName = Sony;
}

public String getName() {
    return nName;
}

}

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher
 public Brand getName() 

It should return a String right?

Hope that helps! (Sorry for the delay!)

Spoiler Alert!

package com.example.model;


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

        private final String mName;

        private Brand(String name) {
            this.mName = name;

        }

        public String getDisplayName(){
            return mName;
        }


}
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Sebastian,

I am not sure I can help. But here are my suggestions:

public enum Brand {
private String nName; //semicolon added

Brand(String Sony) {// access modifier "public" added
    nName = Sony;
}

public String getName() {
    return nName;
}

}

Have you created an instance of Brand inside a class with a main method and gave it a String a an argument?

Like this?

Brand brand = new Brand ("Sony");//your constructor expects a String argument

Let us know if you need more help

Grigorij

Sebastian Portocarrero Leon
Sebastian Portocarrero Leon
3,871 Points

Hi Grigorij thanks for the answer but i need help with enum code challenge task 1 that is:

Okay, so for our Boombox app, let's allow it to emulate different kinds of radios that we've carried around throughout the years.

I've started building the Brand Enum can you please add JVC, Sony, Coby and Apple?

package com.example.model;

public enum Brand {
  // Your code here 
  JVC("JVC"),
  SONY("Sony"),
  COBY("Coby"),
  APPLE("Apple");
  private Brand nName;
    Brand(Brand Sony) {
        nName = Sony;
    }

    public Brand getName() {
        return nName;
    }
}

and the error that i get now is: ./com/example/model/Brand.java:6: error: incompatible types: String cannot be converted to Brand JVC("JVC"),