Passing in a DAUNT Faction Type for Daunt Class

  • Thread starter Thread starter Robben
  • Start date Start date
  • Tags Tags
    Class Type
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
8 replies · 2K views
Robben
Messages
166
Reaction score
2

Homework Statement



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?

Homework Equations



None

The Attempt at a Solution



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

public class Daunt {

public Daunt() {
}

}
 
Physics news on Phys.org
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
Java:
Class Daunt {
    Faction myenum = Faction.DAUNT;
    ...
}
as an attribute in the Daunt class and a getter to retrieve it.
 
jedishrfu said:
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
Java:
Class Daunt {
    Faction myenum = Faction.DAUNT;
    ...
}
as an attribute in the Daunt class and a getter to retrieve it.

I see so then in order to retrieve it I will do

Java:
public getMyenum() {
    return myenum;
}
 
jedishrfu said:
Yes that's one way.

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()?
 
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.
 
Mark44 said:
@Robben, you need to include the return type (Faction) in your definition of getMyenum.

Java:
public Faction getMyenum() {
    return myenum;
}

Understood. Thank you!