Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java problem Hand.txt DIAMOND:ACE DIAMOND:KING DIAMOND:QUEEN DIAMOND:JACK DIAMOND:TEN Card Class package carddeck.service.classes; /*Task 2: Import necessary user defined classes*/ public class Card { private CardSign

Java problem

Hand.txt

DIAMOND:ACE DIAMOND:KING DIAMOND:QUEEN DIAMOND:JACK DIAMOND:TEN

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; } }

CardGame 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

System.out.println("Dealer Wins :-(");

else if (score == 0)

System.out.println("Its a draw");

else 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;

}

}

}catch(IOException ioe){

System.out.println("The file can not be read");

}catch(IllegalArgumentException ia){

System.out.println(ia.getMessage());

} catch(NullPointerException np){

System.out.println(np.getMessage());

}

}

}

CardSign 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

rndVal= (int)(Math.random()*(range)+min);

System.out.println("Random number is " + rndVal);

}

}

}

image text in transcribed

image text in transcribed

Expected Output:

image text in transcribed

Your task is to write a Java program that will implement the iPoker game. Some of the java classes that you will be needing has been provided with this assignment. Please go through them. The places where you need to add your code has been marked with a "Task" comment. larlnts rce You will download and modify the given source files from the course webiste: o Card.java: implements a service class called "Card" that stores the sign and value ofa card using enum types CardSign and CardValue, respectively. You will need to modify this file. o CardSign.java: has the declaration of the CardSign enum datatype. No modification needed. CarGame.java: has the client class. Please go through the comments. It should be self- explanatory. You will need to modify this file o Your task is to write a Java program that will implement the iPoker game. Some of the java classes that you will be needing has been provided with this assignment. Please go through them. The places where you need to add your code has been marked with a "Task" comment. larlnts rce You will download and modify the given source files from the course webiste: o Card.java: implements a service class called "Card" that stores the sign and value ofa card using enum types CardSign and CardValue, respectively. You will need to modify this file. o CardSign.java: has the declaration of the CardSign enum datatype. No modification needed. CarGame.java: has the client class. Please go through the comments. It should be self- explanatory. You will need to modify this file o

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions