Question: *I WROTE THE CODE BUT SOME PARTS ARE MISSING .* *MISSING PARTS ARE SPECIFIED WITH TODO.* *This is for CS 102 Java class.* * I

*I WROTE THE CODE BUT SOME PARTS ARE MISSING .*

*MISSING PARTS ARE SPECIFIED WITH "TODO".*

*This is for CS 102 Java class.*

* I cannot use switch, conditional operator, break, continue, label, system.exit or exceptions, recursion. *

*I WROTE THE CODE BUT SOME PARTS ARE MISSING .* *MISSING PARTS

ARE SPECIFIED WITH "TODO".* *This is for CS 102 Java class.* *

I cannot use switch, conditional operator, break, continue, label, system.exit or exceptions,

recursion. * Here is my code. ===================================== package cardgame; import java.util.ArrayList; //

Cardgame // author: // date: public class CardGame { // properties Cards

fullPack; ArrayList players; ScoreCard scoreCard; Cards[] cardsOnTable; int roundNo; int turnOfPlayer; //

constructors public CardGame( Player p1, Player p2, Player p3, Player p4) {

Here is my code.

=====================================

package cardgame;

import java.util.ArrayList;

// Cardgame // author: // date: public class CardGame { // properties Cards fullPack; ArrayList players; ScoreCard scoreCard; Cards[] cardsOnTable; int roundNo; int turnOfPlayer; // constructors public CardGame( Player p1, Player p2, Player p3, Player p4) { // ToDo } // methods public boolean playTurn( Player p, Card c) { // Todo return false; } public boolean isTurnOf( Player p) { // ToDo return false; } public boolean isGameOver() { // ToDo return false; } public int getScore( int playerNumber) { // ToDo return -1; } public String getName( int playerNumber) { // ToDo return "Not yet implemented"; } public int getRoundNo() { // ToDo return -1; } public int getTurnOfPlayerNo() { // ToDo return -1; } public Player[] getWinners() { // ToDo return null; } public String showScoreCard() { return scoreCard.toString(); } }

================================

package cardgame;

// Player - Simple card game player with name and hand of cards // author: // date: public class Player { // properties String name; Cards hand; // constructors public Player( String name) { // ToDo } // methods public String getName() { return name; } public void add( Card c) { // ToDo } public Card playCard() { // ToDo return null; } } // end class Player

===============================

package cardgame;

// ScoreCard - Maintains one integer score per player, for any number of players // Caution: invalid playernumbers result in run-time exception! // author: // date: public class ScoreCard { // properties int[] scores; // constructors public ScoreCard( int noOfPlayers) { scores = new int[noOfPlayers]; // init all scores to zero for ( int i = 0; i

===================================

package cardgame;

// Cards - Maintains a collection of zero or more playing cards. // Provides facilities to create a full pack of 52 cards // and to shuffle the cards. // author: // date: public class Cards { final int NOOFCARDSINFULLPACK = 52; // properties Card[] cards; int valid; // number of cards currently in collection // constructors public Cards( boolean fullPack) { cards = new Card[ NOOFCARDSINFULLPACK ]; valid = 0; if ( fullPack) createFullPackOfCards(); } // methods public Card getTopCard() { Card tmp;

if ( valid

===================================

package cardgame;

/** * Card - a single playing card * @author * @version */ public class Card { final String[] SUITS = { "Hearts", "Diamonds", "Spades", "Clubs"}; final String[] FACES = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; final int NOOFCARDSINSUIT = 13; // properties int cardNo; // constructors public Card( int faceValue, int suit ) { cardNo = faceValue + suit * NOOFCARDSINSUIT; } public Card( int cardNumber) { cardNo = cardNumber; } public int getFaceValue() { return cardNo % NOOFCARDSINSUIT; } public int getSuit() { return cardNo / NOOFCARDSINSUIT; } public String toString() { return FACES[ getFaceValue() ] + " of " + SUITS[ getSuit() ]; } public boolean equals( Card c) { // ToDo return false; } public int compareTo( Card c) { // ToDo return 0; } }

====================================

import java.util.Scanner; import cardgame.*;

// CardGameTest // author: // date: public class CardGameTest { public static void main( String[] args) { Scanner scan = new Scanner( System.in); System.out.println( "Start of CardGameTest "); // CONSTANTS // VARIABLES Card c; Cards cards; ScoreCard scores; Player p; CardGame game; // PROGRAM CODE // test Card class c = new Card( 1); System.out.println( c); System.out.println(); // test Cards class cards = new Cards( true); cards.addTopCard( c); cards.testOnlyPrint(); // remove method after testing! // test ScoreCard class scores = new ScoreCard( 4); scores.update( 3, 1); scores.update( 1, 2); System.out.println( " " + scores ); // test Player class // ToDo // test CardGame class too? // Todo // Once you have all the bits working, complete the MyCardGame program // that provides a menu allowing any of the players to play their card, // an option to see the score card, and one to quit the game at any time. // When the game is over it should print out the winners. System.out.println( " End of CardGameTest " ); } } // end of class CardGameTest

=======================================

import java.util.Scanner; import cardgame.*;

// MyCardGame - provides a menu allowing any of the players to play their card, // an option to see the score card, and one to quit the game at any time. // When the game is over it dislays the winners. // author: // date: public class MyCardGame { public static void main( String[] args) { Scanner scan = new Scanner( System.in); System.out.println( "Start of MyCardGame "); // CONSTANTS final int MENU_EXIT = 0; final int MENU_PLAY_P1 = 1; final int MENU_PLAY_P2 = 2; final int MENU_PLAY_P3 = 3; final int MENU_PLAY_P4 = 4; final int MENU_SCORES = 5; // VARIABLES Player p1, p2, p3, p4; CardGame game; int selection; // PROGRAM CODE

// create players... p1 = new Player( "p1"); p2 = new Player( "p2"); p3 = new Player( "p3"); p4 = new Player( "p4"); // create game with the 4 players... game = new CardGame( p1, p2, p3, p4); // display menu, get and process selection, until exit do { // display menu System.out.println(); System.out.println( "MyCardGame Round: " + game.getRoundNo() + "\t TurnOfPlayer: " + game.getTurnOfPlayerNo() ); System.out.println(); System.out.println( MENU_PLAY_P1 + " - Player " + MENU_PLAY_P1 + " plays" ); System.out.println( MENU_PLAY_P2 + " - Player " + MENU_PLAY_P2 + " plays" ); System.out.println( MENU_PLAY_P3 + " - Player " + MENU_PLAY_P3 + " plays" ); System.out.println( MENU_PLAY_P4 + " - Player " + MENU_PLAY_P4 + " plays" ); System.out.println( MENU_SCORES + " - Show scores" ); // ask for and get selection System.out.println(); System.out.println( "Selection (" + MENU_EXIT + " to exit): "); selection = scan.nextInt(); // process selection if ( selection == MENU_PLAY_P1 ) play( p1, game); else if ( selection == MENU_PLAY_P2 ) play( p2, game); else if ( selection == MENU_PLAY_P3 ) play( p3, game); else if ( selection == MENU_PLAY_P4 ) play( p4, game); else if ( selection == MENU_SCORES ) // ToDo ~ System.out.println( game.showScoreCard() ); System.out.println( "ToDo..." ); else if ( selection != MENU_EXIT) System.out.println( "Invalid selection! " ); } while ( selection != MENU_EXIT);

// display winners... // ToDo ~ game.isGameOver(); ? game.getWinners(); System.out.println( "ToDo..." ); System.out.println( " End of MyCardGame " ); }

// ToDo... // get the card, c, that player p wants to play // pass c to the game, see if it accepted c from p // if game didn't accept the card, give c back to the player! // return accepted. private static boolean play( Player p, CardGame game) { Card c; boolean accepted; accepted = false; // ToDo...

return accepted; } } // end class MyCardGame

========================================

The Problem... Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game. The Problem... Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game

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!