For an exercise I'm making a program that initializes a single virtual playing card, and I'm also using an enum as the main class as shown below.
The problem is this block over here
In the below code block I try to input both suit and rank into this variable, but Intellij says inputting "Jack" as the suit isn't a statement.Error Message "not a statement"(it's under "Jack").
public static void main(String[] args)
{
CardMaker Card = (Hearts, "Jack");
Card.printCard();
}
Code:
import java.util.Arrays;
public enum CardMaker
{
Hearts, Spades, Clubs, Diamond;
CardMaker Suit;
String[] Ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
String Rank = "";
CardMaker(CardMaker Suit, String Rank)
{
this.Rank = Rank;
this.Suit = Suit;
if(Arrays.binarySearch(Ranks, Rank) < 0)
{
System.out.println("Invalid Rank try again");
System.exit(1);
}
}
private String[] Card = {String.valueOf(Suit), Rank};
CardMaker()//This stops a error I forgot which one
{
}
private String printCard()
{
System.out.printf("Here's your card '%1$s" ,Card.toString());
return Card.toString();
}
public static void main(String[] args)
{
CardMaker Card = (Hearts, "Jack");
Card.printCard();
}
}
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html The tutorial told me how enum constructors work, but 1st didn't tell me that you can't make an object of an enum.
2nd it didn't say that you couldn't initialize a object of an enum type(Please explain how that works and if it relates to my issue).
(This isn't a dupe as while it's the same kind of question I'm asking it for this project in java which is different then c# I ignored other languages as this is a java syntax question)