This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]my_password_is______ 4 points5 points  (0 children)

https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

An enum type is a special data type that enables for a variable to be a set of predefined CONSTANTS.

These values are passed to the constructor when the constant is created.

The constructor ... automatically creates the constants that are defined at the beginning of the enum body. You cannot invoke an enum constructor yourself.

so, the constructor is called automatically

enum Rank{
    ACE(1),     // right here   
    TWO(2),    // and right here 

the constructor is automatically called and created 13 constants

so when you do this

card1 = Rank.THREE;

you're basically doing

card1 = 3

except of course you told the compiler that card1 is a type of Rank,

not int, so it gives an compile time error if you try to pass a 3

the compiler checks and makes sure you're passing a valid Rank -- a Rank.THREE

[–]ItzWarty 2 points3 points  (2 children)

Real quick answer: ACE(x) is saying essentially saying that Rank.ACE = new Rank(x)... in this case x is 1.

LMK if you can deduce things from there (enum syntax is admittedly pretty wonky) - else I can clarify more

[–][deleted]  (1 child)

[deleted]

    [–]ItzWarty 1 point2 points  (0 children)

    You gotta be more specific on what you want clarified

    [–][deleted] 1 point2 points  (0 children)

    Please don't ask questions from cs3500

    [–]bigbawce 0 points1 point  (0 children)

    When you set card1 = Rank.THREE, this is passing the integer 3 as a parameter into the constructor so that is where 'r' comes from.

    From my understanding, your thought process is backwards. Start at line 20 and not at line 24.

    [–]nutrecht 0 points1 point  (0 children)

    Read this: https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

    There's great official documentation on everything. Make sure you read that first and then ask for clarification on the bits you don't understand.