Using MS Word write down in plain English all the steps need
Using MS Word, write down in plain English, all the steps needed to achieve the end result of Challenge #4. Be as specific as possible.
Psuedo code What would be the steps i need to do to start this problem. Just the steps.
Write a program that will produce output similar to the output below:
User: hearts 8
User Totals: 8
Computer: spades 2
Computer Totals: 2
User: hearts 4
User Totals: 12
Computer: spades 8
Computer Totals: 10
User: hearts 1
User Totals: 13
Computer: spades 10
Computer Totals: 20
User: hearts 3
User Totals: 16
Computer: spades 4
Computer Totals: 24
User won because computer went over 21
Other messages that could be displayed are:
\"User won this round.\"
\"Computer won this round.\"
\"Computer won because user went over 21\"
\"User won because computer went over 21\"
“Both lost since both user and computer totals went over 21\"
To accomplish this, you will need to create 2 classes, a domain Card class, and a driver class.
The Card class will have the following 2 instance variables:
private String suit; //Clubs, Diamonds, Hearts, Spade
private int cardValue; // 1 - 11;
The Card class will also contain the following:
Constructor, receiving card value and card name as input parameters.
Setters & Getters for each of the 2 instance variables (cardValue & suit)
toString – to display content of card, including card suit and card value.
The Driver class will have the following global variables:
public static int userTotals = 0;
public static int computerTotals = 0;
public static Random myRan = new Random();
The Driver class will also have the following methods:
Main method, which will call 2 methods inside of a loop:
//A loop in main will include these 3 statements:
drawUserCard();
drawComputerCard();
System.out.println(\"\ \");
After the loop in main finishes, there will be a set of if-else-if statements to determine whether the user won, the computer won, or both were tied, or both lost. Here’s the beginning of the if-statements needed:
if (userTotals > computerTotals && userTotals <= 21)
{
System.out.println(\"User won this round.\");
}
else if …
As a result of all the if-statements, each of the following error messages should be displayed:
“User won because computer went over 21”
\"User won this round.\"
\"Computer won this round.\"
\"Computer won because user went over 21\"
\"User won because computer went over 21\"
“Both lost since both user and computer totals went over 21\"
See the skeleton for the drawUserCard() method.
package blackjack;
/**
*
* @author cristy
*/
public class Card
{
private String suit; //Clubs, Diamonds, Hearts, Spade
private int cardValue; // 1 - 11;
public Card (String aSuit, int aCardValue)
{
...
}
// all the getters and setters for each of the 2 instance attributes
public String toString()
{
return \"Suit \" + suit + \"\ \" + \"Card Value \" + cardValue;
}
}
package blackjack;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author mtsguest
*/
public class BlackJack {
public static int userTotals = 0;
public static int computerTotals = 0;
public static Random myRan = new Random();
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
while (...)
{
drawUserCard();
drawComputerCard();
System.out.println(\"\ \");
}
if (userTotals > computerTotals && userTotals <= 21)
{
System.out.println(\"User won this round.\");
}
// else if (...)
// ...
}
public static void drawUserCard()
{
int userCard = myRan.nextInt(11) + 1;
int cardSuite = myRan.nextInt(4) + 1;
String suiteName;
if (cardSuite == 1)
suiteName = \"clubs\";
else if (cardSuite == 2)
suiteName = \"hearts\";
else if (cardSuite == 3)
suiteName = \"diamonds\";
else
suiteName = \"spades\";
Card myCard = new Card(suiteName, userCard);
System.out.println(\"User Card: \" + myCard);
userTotals += userCard;
}
public static void drawComputerCard()
{
//do similar logic as drawUserCard
}
}
Solution
public Card drawFromDeck()
{
Random generator = new Random();
int index=0;
do {
index = generator.nextInt( 52 );
} while (cards[index] == null);
i--;
Card temp = cards[index];
cards[index]= null;
return temp;
}
public int getTotalCards()
{
return i;
}
}



