Please write in Java The complier I am using is Eclispe Writ

Please write in Java. The complier I am using is Eclispe

Write a class that defines an enumerated type named Rank with values ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king.

The main method should do the following:

•Declare variables highCard, faceCard, card1, and card2 of type Rank.

•Assign highCard to be an ace, faceCard to be a jack, queen or king (your choice), and card1 and card2 to be two different numbered cards (two through ten - your choice).

• Print a line, using the highCard and faceCard objects, in the following format: A blackjack hand: ace and faceCard

• Declare two variables card1Val and card2Val of type int and assign them the face value of your card1 and card2 objects. Use your card1 and card2 variables and the ordinal method associated with enumerated types. Remember that the face value of two is 2, three is 3, and so on so you need to make a slight adjustment to the ordinal value of the enumerated type.

• Print two lines, using the card1 and card2 objects and the name method, as follows: A two card hand: (print card1 and card2) Hand value (print the sum of the face values of the two cards)

Example Output: ----------------------------------------------------------------------------------

Quick AccessEl Quick Access EB Console S3 Cards [Java Application] C:Program FilesUa A two card hand: three and five Hand value: 8

Solution

import java.util.*;
import java.lang.*;
import java.io.*;

class RankNames //class with Rank enum
{
public enum Rank { ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king};
}
class RankEnum
{
  
   public static void main (String[] args)
   {
       RankNames.Rank highCard = RankNames.Rank.ace; //use class name and enum name with variables
   RankNames.Rank faceCard = RankNames.Rank.queen;
   RankNames.Rank card1 = RankNames.Rank.three;
   RankNames.Rank card2 = RankNames.Rank.five;
  
   System.out.println(\"A blackjack hand: ace and queen\");
   int card1Val = 3;
   int card2Val = 5;
   System.out.println(\"A two card hand: \"+ card1 +\" and \"+card2); //print card values
   System.out.println(\"hand value: \"+ (card1Val+card2Val)); //print corresponding integer values
  
   }
}

output:

Success time: 0.03 memory: 711168 signal:0

Please write in Java. The complier I am using is Eclispe Write a class that defines an enumerated type named Rank with values ace, two, three, four, five, six,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site