Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA- ECLIPSE I was given a homework to create, shuffle and distribute a card deck amongst four players, and then play a game with specific

JAVA- ECLIPSE

I was given a homework to create, shuffle and distribute a card deck amongst four players, and then play a game with specific rules.

The comments I received were

- 25 - For some reason the multiplication for 2S, Subtraction for 5D and 5H, AH-AD plus one and AS-AC random pick are skipped and the pile stays the same. Also forgot to add +5 to the pile for 5S-5C.

-10 - The rule for QH is that the pile resets to 0 but you add +10 just like the rest of the queens

-10 - The game round ends when the pile reaches atleast 101 you stopped the game at exactly 100

But the problem is, I fixed these in my code and some still don't run. Here is my code in relevance to the comments. For example, on the method, some of the rules are executed just fine, for example when 'J' is played, the value of the pile gets -10, but for others, like for the Aces, the pile value stays the same and doesn't change.

public static int getNewPileValue(int pileValue, String card) {

if (card.charAt(0) == 'A') {

if (card.charAt(1) == 'H' || card.charAt(1) == 'D') {

pileValue = pileValue+1;

}

if (card.charAt(1) == 'S' || card.charAt(1) == 'C') {

pileValue = (int)((Math.random()* 200)-100);

}

}

if (card.charAt(0) == '2' && card.charAt(1) == 'S') {

pileValue = (pileValue*2);

}

if (card.charAt(0) == '5' && card.charAt(1) == 'H' || card.charAt(0) == '5' && card.charAt(1) == 'D') {

pileValue = (pileValue-5);

}

if (card.charAt(0) == 'J') {

pileValue = pileValue - 10;

}

if (card.charAt(0) == 'Q' && card.charAt(1) == 'H') {

pileValue = 0;

}

if (card.charAt(0) == 'K') {

;

}

if (card.charAt(0) == 'Q') {

pileValue += 10;

} else if (card.charAt(0) == '1' && card.charAt(1) == '0') {

pileValue = 100;

} else {

char character = card.charAt(0);

int numberFromString = Character.getNumericValue(character);

if (numberFromString == 2 || numberFromString == 3 || numberFromString == 4 || numberFromString==5|| numberFromString == 6

|| numberFromString == 7 || numberFromString == 8 || numberFromString == 9)

pileValue = pileValue + numberFromString;

}

return pileValue;

}

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions