Question: JAVA. Card Class package carddeck.service.classes; /*Task 2: Import necessary user defined classes*/ public class Card { private CardSign sign; private CardValue value; public Card(CardSign sign,

JAVA.

Card Class

package carddeck.service.classes; /*Task 2: Import necessary user defined classes*/ public class Card { private CardSign sign; private CardValue value; public Card(CardSign sign, CardValue value) { // constructor this.sign = sign; this.value = value; } public CardSign getSign() { return this.sign; } public CardValue getValue() { return this.value; } public String toString() { return "Card: " + this.value + " of " + this.sign; } }

Card Game Class

package library.client.classes; import java.util.Scanner; import java.io.File; import java.io.IOException;

/*Task 2: Import necessary user defined classes */

class CardGame{ Card [] userHand; Card [] dealerHand;

private void generateDealerHand(){ /*Task 5: Implement the class method generateDealerHand() in CardGame class. This method will use a random generator to generate signs, and values of the cards for the dealer.*/ } private int getScore(){ /*Task 3: Implement the class method getScore() in CardGame class. This method will compare the cards of the dealer and player and provide a score. If the score is zero, it means the game is a tie. If the score is positive, then the player has won the game. You should implement other methods as needed.*/ } public static void main(String []args){ //arg[0]: file containing user hand CardGame game=new CardGame(); //read the the files from text files int counter=0; Card aCard; Scanner scan; String str; try { File myFile=new File(args[0]); scan=new Scanner(myFile); while(scan.hasNextLine()){ str=scan.nextLine(); String []tok=str.split(":"); /*Task 4: Implement the code in the main method of the CardGame class, that will take the values read from the text file, create Card objects and populate the array Hand. userHand is an attribute of the CardGame class.*/ } //lets play iPoker!! //User interactive part String option1; scan = new Scanner(System.in); int score; while(true){ System.out.println("Select an option:"); System.out.println("Type \"P\" to play a round of iPoker"); System.out.println("Type \"Q\" to Quit"); option1=scan.nextLine(); switch (option1) { case "P": game.generateDealerHand(); score=game.getScore(); game.printHand();///First print out the hands System.out.println(" Compare the two hands:"); if(score 0) System.out.println("Congrats You win !!"); else System.out.println("Somethings wrong!"); break; case "Q": System.out.println("Quitting program"); System.exit(0); default: System.out.println("Wrong option! Try again"); break; } }

Enumeration Class

package carddeck.service.classes; public enum CardSign {SPADE,CLUB,DIAMOND,HEART};

RndGen Class

class RndGen{

public static void main(String [] args){ //generate 10 random integers between 7 (min value) and 15 (max value) int min=7; int max=15; int rndVal; int range = max-min+1; for(int i=0;i

Task 1: declare an enum type called CardValue with the following values {ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING}. This should be done in a separate java source file and placed in the package carddeck.service.classes;

Task 2: Import necessary user defined classes in the Card.java and CardGame.java

Task 3: Implement the class method getScore() in CardGame class. This method will compare the cards of the dealer and player and provide a score. If the score is zero, it means the game is a tie. If the score is positive, then the player has won the game.

Task 4: Implement the code in the main method of the CardGame class, that will take the values read from the text file, create Card objects and populate the array userHand. userHand is an attribute of the CardGame class.

Task 5: Implement the class method generateDealerHand() in CardGame class. This method will use a random generator to generate signs, and values of the cards for the dealer.

OUTPUT

JAVA. Card Class package carddeck.service.classes; /*Task 2: Import necessary user defined classes*/

Select an option: Type "P" to play a round of iPoker Type "Q' to Quit User's Hand: Card: ACE of DIAMOND Card: NINE of DIAMOND Card: QUEEN of DIAMONID Card: JACK of HEART Card: TEN of DIAMOND Dealer's Hand: Card: ACE of DIAMOND Card: KING of SPADE Card: JACK of CLUB Card: SEVEN of SPADE Card: SLX of CLUB 6 Compare the two hands: Its a draw Select an option: Type "P" to play a round of iPoker Type " to Quit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!