Question: I need help trying to finish my program!!! Please help it's due Friday 12 at 8:00pm!!! The directions had me a little confused with how
I need help trying to finish my program!!! Please help it's due Friday 12 at 8:00pm!!! The directions had me a little confused with how many classes I was supposed to create, but hopefully you can help me with this and having it run with the right output!
Enhance your previous Java program by allowing for any number of basic card games. For now, you for create two games (war and black jack (21)) that inherit from the same template structure. Both of these games are still simplified versions of the real-life games. The requirements for this assignment are as follows:
- Create a template interface called CardGame that requires four functions: setupGame, playTurn, runSimulation, and printResults. Each of these functions takes no arguments, nor will they return anything. Be sure to comment the purpose of each in the template.
- Create a new class, War, that implements the CardGame interface. Explicitly override the four previous function by including the @Override designation for each function (in both subclasses).
- This class can have as many private member variables as needed and reasonable.
- Move the game procedural code into the appropriate portions of this class from the main function of PlayGame class. When completed with this assignment, the PlayGame class will only insatiate an instance of the War (and BlackJack) class and call the necessary functions. All functions in the War class must work intuitively, allowing the game to easily be stopped or restarted if desired.
- The setupGame function, should work as its name implies. Print the welcome message and initialize all variables. Generically specify the class name in the welcome message by calling the getClass().getName() function.
- The playTurn function should proceed in much the same manner as the previous assignment, but without the loop. It will almost certainly be necessary to track the number of turns as well as the accumulated results of each turn. This will mean more member variables in this class.
- The remaining two functions should perform tasks appropriate to their designations and the output below. For now, the simulation should still only run four times.
- In the main procedural portion of the program, declare a CardGame object and then insatiate it as an instance of the War class and run the simulation by calling the necessary functions.
- Repeat the above steps for the BlackJack class. The only significant difference between our versions of war and black jack games is that black jack uses two cards per player and adds the results for comparison. This version of blackjack does not allow for hitting, folding, splitting, etc... Recall, in this case still, an Ace is treated as a rank of 1 (lowest card).
The output should look something like this -- user inputs are in bold blue type:
Shall we play a game? (War) Draw #1: Six of Diamonds versus Queen of Hearts Player 2 wins Draw #2: Six of Diamonds versus Six of Diamonds It's a draw Draw #3: Ten of Diamonds versus Seven of Clubs Player 1 wins Draw #4: Eight of Spades versus Ace of Clubs Player 1 wins The game ran for 4 turns. Player 1 won 2 times. Player 2 won 1 times. Players tied 1 times. Shall we play a game? (BlackJack) Draw #1: Six of Diamonds and Six of Hearts versus Six of Diamonds and Nine of Clubs Player 2 wins Draw #2: Six of Clubs and Three of Clubs versus Six of Clubs and Two of Hearts Player 1 wins Draw #3: Ace of Hearts and Jack of Spades versus Ace of Hearts and King of Spades Player 2 wins Draw #4: Two of Hearts and Four of Spades versus Five of Hearts and Ace of Hearts It's a draw The game ran for 4 turns. Player 1 won 1 times. Player 2 won 2 times. Players tied 1 times.
All member variables, unless otherwise specified, must be private or protected. You are allowed to create static constants as appropriate and within reason. Accessor functions must be used to view or modify member variables outside the scope of the class. Assignments with public member variables will not be accepted. All classes and files must adhere to meaningful and conventionally formatted names.
This is what I have for my program so far.....
/////////////////////////////////////////
CardGame.java
public class CardGame {
//Member Variables
private int cardRank;
private int cardSuit;
//13 string rank names
private final static String[]RANKNAMES = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "King", "Queen", "Jack"};
//4 string suit names
private final static String[]SUITNAMES = {"Hearts", "Diamonds", "Spades", "Clubs"};
@Override
public String toString(){
return + " " + topFace ; //return the card rank of the card suit
}
public void SetupGame(){
}
@Override
public String toString(){
return + " " + topFace ; //return the card rank of the card suit
}
public void PlayerTurn(){
}
@Override
public String toString(){
return + " " + topFace ; //return the card rank of the card suit
}
public void RunSimulation(){
}
@Override
public String toString(){
return + " " + topFace ; //return the card rank of the card suit
}
public void PrintResults(){
}
//Constructors
public CardGame( int cardSuit, int cardRank) {
//this specific card suit is equal to a card suit
this.cardSuit = cardSuit;
//this specific card rank is equal to a card rank
this.cardRank = cardRank;
}
public CardGame() {
//this specific card suit is equal to a card suit
this.cardSuit = 0;
//this specific card rank is equal to a card rank
this.cardRank = 1;
}
//Accessor Functions
public void getcardSuit(int cardSuit){
this.cardSuit = cardSuit; //this specific card suit is equal to a card suit
}
public int getcardSuit(){ //get card suit function
return cardSuit; //return the card suit
}
public void getcardRank(int cardRank){
this.cardRank = cardRank; //this specific card rank is equal to a card rank
}
public int getcardRank(){ //get card rank function
return cardRank; //return the card rank
}
public void drawCard(){ //draw a card function
this.cardSuit = ((int)(Math.random() * 4)); //random number generator for the card suit
this.cardRank = ((int)(Math.random() * 13)); //random number generator for the card rank
}
//override the function
@Override
//return the string rank of the card
public String toString(){
return RANKNAMES[cardRank] + " of " + SUITNAMES[cardSuit] ; //return the card rank of the card suit
}
//Member Functions
}
/////////////////////////////////////////
/////////////////////////////////////////
PlayerTurn.java
public class PlayerTurn {
//member variables
int turns = 4;
//player 1 initiates a new card every time
CardGame player1Card = new SetupGame();
//player 1 initiates a new card every time
CardGame player2Card = new SetupGame();
//war player turn
for(int i = 0; i < 4; i++){ //the variable i equals the integer 0, i has to be less than 4
player1Card.drawCard(); //player number 1 draws a card and will draw one card 4 rounds
player2Card.drawCard(); //player number 2 draws a card and will draw one card 4 rounds
System.out.println("Draw # " + (i + 1) + " " + player1Card + " versus " + player2Card );
//blackjack player turn
for(int i = 0; i < 4; i++){ //the variable i equals the integer 0, i has to be less than 4
player1Card.drawCard(); //player number 1 draws a card and will draw one card 4 rounds
player2Card.drawCard(); //player number 2 draws a card and will draw one card 4 rounds
System.out.println("Draw # " + (i + 1) + " " + player1Card + " and " + player1Card + " versus " + player2Card + " and " + player2Card);
}
/////////////////////////////////////////
/////////////////////////////////////////
PlayGame.java
public class PlayGame{
public static void main(String args[])
{
//ask the user if they want to play a game of War
System.out.println("Shall we play a game? (War)");
//player 1 initiates a new card every time
CardGame player1Card = new CardGame();
//player 1 initiates a new card every time
CardGame player2Card = new CardGame();
for(int i = 0; i < 4; i++){ //the variable i equals the integer 0, i has to be less than 4
player1Card.drawCard(); //player number 1 draws a card and will draw one card 4 rounds
player2Card.drawCard(); //player number 2 draws a card and will draw one card 4 rounds
System.out.println("Draw # " + (i + 1) + " " + player1Card + " versus " + player2Card );
if(player1Card.getcardRank() > player2Card.getcardRank()) //if player 1 card is greater than player 2 then...
{
//state that player 1 wins
System.out.println("Player 1 wins");
}
else if(player1Card.getcardRank() == player2Card.getcardRank()){
//state that if both players end up with the same value on the card then its a draw
System.out.println("It's a draw");
}
else {
//state that player 2 wins
System.out.println("Player 2 wins");
}
// System.out.println("The game ran for" + 4 + "turns.");
// System.out.println("Player 1 won" + 2 + "times.");
// System.out.println("Player 2 won" + 1 + "times.");
// System.out.println("Players tied" + 1 + "times.");
}
//ask the user if they want to play a game of BlackJack
System.out.println("Shall we play a game? (BlackJack)");
//player 1 initiates a new card every time
CardGame player1Card = new CardGame();
//player 1 initiates a new card every time
CardGame player2Card = new CardGame();
for(int i = 0; i < 4; i++){ //the variable i equals the integer 0, i has to be less than 4
player1Card.drawCard(); //player number 1 draws a card and will draw one card 4 rounds
player2Card.drawCard(); //player number 2 draws a card and will draw one card 4 rounds
System.out.println("Draw # " + (i + 1) + " " + player1Card + " and " + player1Card + " versus " + player2Card + " and " + player2Card);
if(player1Card.getcardRank() > player2Card.getcardRank()) //if player 1 card is greater than player 2 then...
{
//state that player 1 wins
System.out.println("Player 1 wins");
}
else if(player1Card.getcardRank() == player2Card.getcardRank()){
//state that if both players end up with the same value on the card then its a draw
System.out.println("It's a draw");
}
else {
//state that player 2 wins
System.out.println("Player 2 wins");
}
System.out.println("The game ran for " + 4 + " turns.");
System.out.println("Player 1 won " + 2 + " times.");
System.out.println("Player 2 won " + 1 + " times.");
System.out.println("Players tied " + 1 + " times.");
}
}
}
/////////////////////////////////////////
/////////////////////////////////////////
PrintResults.java
public class PrintResults {
System.out.println("The game ran for" + 4 + "turns.");
System.out.println("Player 1 won" + 2 + "times.");
System.out.println("Player 2 won" + 1 + "times.");
System.out.println("Players tied" + 1 + "times.");
System.out.println("The game ran for" + 4 + "turns.");
System.out.println("Player 1 won" + 2 + "times.");
System.out.println("Player 2 won" + 1 + "times.");
System.out.println("Players tied" + 1 + "times.");
}
/////////////////////////////////////////
/////////////////////////////////////////
RunSimulation.java
public class RunSimulation {
if(player1Card.getcardRank() > player2Card.getcardRank()) //if player 1 card is greater than player 2 then...
{
//state that player 1 wins
System.out.println("Player 1 wins");
}
else if(player1Card.getcardRank() == player2Card.getcardRank()){
//state that if both players end up with the same value on the card then its a draw
System.out.println("It's a draw");
}
else {
//state that player 2 wins
System.out.println("Player 2 wins");
}
if(player1Card.getcardRank() > player2Card.getcardRank()) //if player 1 card is greater than player 2 then...
{
//state that player 1 wins
System.out.println("Player 1 wins");
}
else if(player1Card.getcardRank() == player2Card.getcardRank()){
//state that if both players end up with the same value on the card then its a draw
System.out.println("It's a draw");
}
else {
//state that player 2 wins
System.out.println("Player 2 wins");
}
}
/////////////////////////////////////////
/////////////////////////////////////////
SetupGame.java
public class SetupGame {
getClass(War).getName(SetupGame);
//ask the user if they want to play a game of War
System.out.println("Shall we play a game? (War)");
//player 1 initiates a new card every time
CardGame player1Card = new CardGame();
//player 1 initiates a new card every time
CardGame player2Card = new CardGame();
//ask the user if they want to play a game of BlackJack
System.out.println("Shall we play a game? (BlackJack)");
//player 1 initiates a new card every time
CardGame player1Card = new CardGame();
//player 1 initiates a new card every time
CardGame player2Card = new CardGame();
}
/////////////////////////////////////////
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
