1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Enum class

  1. Mar 5, 2015 #1
    1. The problem statement, all variables and given/known data

    Suppose I have an enum class named Faction and one of the constants is named DAUNT. I created a Daunt class of the enum but how can I pass in a DAUNT faction type in for Daunt?


    2. Relevant equations

    None

    3. The attempt at a solution

    Code (Text):
    public enum Faction {
       ALMIGHTY, AMBITION, DAUNT, RESTLESS, CAN;
    }

    public class Daunt {

    public Daunt() {
    }

    }
     
  2. jcsd
  3. Mar 5, 2015 #2

    jedishrfu

    Staff: Mentor

    There is no connection between the DAUNT enum and Daunt class other than a similarity in the name

    As an example, you could add a
    Code (Java):

    Class Daunt {
        Faction myenum = Faction.DAUNT;
        ...
    }
     
    as an attribute in the Daunt class and a getter to retrieve it.
     
  4. Mar 5, 2015 #3
    I see so then in order to retrieve it I will do

    Code (Java):

    public getMyenum() {
        return myenum;
    }
     
  5. Mar 5, 2015 #4

    jedishrfu

    Staff: Mentor

    Yes that's one way.
     
  6. Mar 5, 2015 #5
    What will the value of the return type of myenum be? Will it have no value? For example, I won't have to declare int or String into my getter, i.e. public int getMyenum()?
     
  7. Mar 5, 2015 #6
    Actually, I figured it out. It will be Faction. Thank you very much! I should have never majored in math and should have majored in CS.
     
  8. Mar 5, 2015 #7

    jedishrfu

    Staff: Mentor

    Nah math is cool too.

    Always appreciate what you learn because it will help you learn more.
     
  9. Mar 6, 2015 #8

    Mark44

    Staff: Mentor

    @Robben, you need to include the return type (Faction) in your definition of getMyenum.

    Code (Java):

    public Faction getMyenum() {
        return myenum;
    }
     
  10. Mar 7, 2015 #9
    Understood. Thank you!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted