Passing in a DAUNT Faction Type for Daunt Class

  • Thread starter Thread starter Robben
  • Start date Start date
  • Tags Tags
    Class Type
Click For Summary

Discussion Overview

The discussion revolves around how to properly associate an enum constant named DAUNT with a class named Daunt in a programming context. Participants explore the implementation details of using enums in Java, specifically focusing on defining attributes and methods within the Daunt class.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant notes that there is no inherent connection between the DAUNT enum and the Daunt class aside from their similar names.
  • Another suggests adding a Faction attribute to the Daunt class to hold the value of the DAUNT enum, along with a getter method to retrieve it.
  • A participant questions the return type of the getter method, wondering if it should be declared as an int or String.
  • One participant later clarifies that the return type of the getter method will be Faction.
  • Another participant emphasizes the importance of including the return type in the method definition.

Areas of Agreement / Disagreement

Participants generally agree on the approach to associate the enum with the class, but there are varying levels of understanding regarding method return types and implementation details. The discussion remains somewhat unresolved as participants clarify their understanding of the getter method.

Contextual Notes

Some participants express uncertainty about the necessity of declaring return types in method definitions, indicating a potential gap in understanding Java syntax.

Who May Find This Useful

Readers interested in Java programming, particularly those learning about enums and class design, may find this discussion beneficial.

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.
 
Nah math is cool too.

Always appreciate what you learn because it will help you learn more.
 
  • Like
Likes   Reactions: Robben
@Robben, you need to include the return type (Faction) in your definition of getMyenum.

Java:
public Faction getMyenum() {
    return myenum;
}
 
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!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
Replies
11
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K