Question

In: Computer Science

This is the class that needs to be written... import java.util.ArrayList; /** * Deals out a...

This is the class that needs to be written...

import java.util.ArrayList;

/**
* Deals out a game of 5-card-stud.
*
* @author PUT YOUR NAME HERE
* @version PUT THE DATE HERE
*/
public class FiveCardStud
{
private Deck myDeck;
private ArrayList<Hand> players;


/**
* Constructor for objects of class FiveCardStud
*/
/*
Write a constructor for the FiveCardStud class. The constructor
accepts a single integer parameter for the number of players.
The number of players should be from 2 to 6 inclusive.
Make sure to take care of values outside of this range.
For numbers less than 2, set the number to 2 and print
an appropriate message. For numbers greater than 6
set the number to 6 and print an appropriate message.
For each player add a hand to the list of players.
Print out the name of the game.
Don't forget to initialize the fields.
*/

  
/**
* Deal the cards.
*/
/*
Write a method called "deal".
The method should print out a message to let the user know
that the cards have been dealt.
It should remove any old cards from all players hands
from previous games (Hint: there is a fold method in the Hand class.)
It should then shuffle the deck and add 5 cards to each player's hand.
*/
  
  
/**
* Prints out all player's hands.
*/
/*
Write a method called "showCards".
The method should print out each players hand as shown
in the sample output.
*/
}

These are other classes that are already written and do not need to be changed...

import java.util.ArrayList;
import java.util.Iterator;

/**
* Represents a single player's hand in a card game.
*
* @author Derek Green, Mar. 27, 04
* @revised by Allyson Anderson, Nov.1, 06
*/
public class Hand
{
private ArrayList<Card> hand;// contains this players cards

/**
* Constructor for objects of class Hand
*/
public Hand()
{
hand = new ArrayList<Card>();
}
  
/**
* Add a single card to the player's hand.
*/
public void addCard(Card card)
{
hand.add(card);
}
  
/**
* Clear the player's hand.
*/
public void fold()
{
hand.clear();
}
  
/**
* Show the player's cards.
*/
public void displayHand()
{
Iterator<Card> it = hand.iterator();
while(it.hasNext())
{
System.out.println((it.next()).getCard());
}
}
}

import java.util.ArrayList;
import java.util.Iterator;

/**
* Represents a deck of 52 playing cards.
*
* @author Derek Green, Mar. 26, 04
* @revised by Allyson Anderson, Nov. 1, 06
*/
public class Deck
{
private final String[] suits = {"Spades ", "Hearts ", "Clubs ", "Diamonds"};
private final String[] faces = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};

private Card[] card;
private int topCard;
  
/**
* Construct a deck of cards
*/
public Deck()
{
card = new Card[52];
topCard = -1;//deal method will increment topCard
for(int i = 0; i < 52; i++)
{
card[i] = new Card(suits[i/13], faces[i%13]);// brand new deck with all cards in order
}
}
  
/**
* deal() returns the next card or null if the deck is empty.
*/
public Card deal()
{
topCard++;// set topCard to the next card
if(topCard < 52)
{   
return card[topCard];
}
else
{
return null;
}
}
  
/**
* shuffle() randomly generates a sequence of cards for the card array
*/
public void shuffle()
{
topCard = -1;// reset the top card
int nextNumber;
boolean[] available = new boolean[52];// used to select random #'s between 0 and 51 without replacement

for(int i = 0; i < 52; i++)
{
available[i] = true;//all #'s between 0 and 51 are available
}
  
for(int i = 0; i < 52; i++)
{
nextNumber = (int)(Math.random()*52);// select a # from 0 to 51
while(!available[nextNumber])//while nextNumber is not available (i.e. this number has already been used)
{
nextNumber = (int)(Math.random()*52);//try a different number until you find an unused one
}
available[nextNumber] = false;// this number is taken
card[i] = new Card(suits[nextNumber/13], faces[nextNumber%13]);
}
}
  
/**
* Print out the entire deck for testing purposes.
*/
public void testDeck()
{
for(int i = 0; i < 13; i++)
{
System.out.println(card[i].getCard() + "\t" + card[i+13].getCard() + "\t" + card[i+26].getCard() + "\t" + card[i+39].getCard());
}
}
  
/**
* Print out a subset of the deck to test the deal method.
*/
public void testDeal(int cardNumber)
{
ArrayList<Card> hand = new ArrayList<Card>();// hold a hand of cards.
int index = 0;
while(index < cardNumber)
{
hand.add(deal());
index++;
}
  
Iterator<Card> it = hand.iterator();
while(it.hasNext())
{   
Card thisCard = it.next();
System.out.println(thisCard.getCard());
}
}
}

/**
* Represents a single playing card.
*
* @author Derek Green, Mar. 26, 04
* @revised by Allyson Anderson, Nov. 1, 06
*/
public class Card
{
private String suit;
private String face;

/**
* Constructor for objects of class Card.
*/
public Card(String suit, String face)
{
this.suit = suit;
this.face = face;
}

/**
* Returns the suit of the card
*/
public String getSuit()
{
return suit;
}
  
/**
* Returns the face of the card
*/
public String getFace()
{
return face;
}
  
/**
* Returns the suit and face of the card as a single String
*/
public String getCard()
{
return face + "\t" + suit;
}
}

Solutions

Expert Solution


Related Solutions

This is the code that needs to be completed... import java.util.ArrayList; import java.util.Collections; /** * Write...
This is the code that needs to be completed... import java.util.ArrayList; import java.util.Collections; /** * Write a description of class SpellChecker here. * * @author (your name) * @version (a version number or a date) */ public class SpellChecker { private ArrayList words; private DictReader reader; /** * Constructor for objects of class SpellChecker */ public SpellChecker() { reader = new DictReader("words.txt"); words = reader.getDictionary(); } /** * This method returns the number of words in the dictionary. * Change...
import java.util.ArrayList; import java.util.Collections; public class BirthdayList { /** * This is the main process for...
import java.util.ArrayList; import java.util.Collections; public class BirthdayList { /** * This is the main process for class BirthdayList */ public static void main() { System.out.println("\n\tBegin Birthday List Program\n");    System.out.println("Declare an ArrayList for Birthday objects"); // 1. TO DO: Declare an ArrayList to store Birthday objects (3 Pts)       // 2. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts) System.out.printf("\nBirthday List is empty: %s\n", xxx.xxxx() ? "True" : "False");    System.out.println("Add at least five Birthdays to...
import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process...
import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process for the project */ public static void main () { System.out.println("\n\tBegin Item List Demo\n"); System.out.println("Declare an ArrayList to hold Item objects"); ArrayList<Item> list = new ArrayList<Item>(); try { System.out.println("\n Add several Items to the list"); list.add(new Item(123, "Statue")); list.add(new Item(332, "Painting")); list.add(new Item(241, "Figurine")); list.add(new Item(126, "Chair")); list.add(new Item(411, "Model")); list.add(new Item(55, "Watch")); System.out.println("\nDisplay original Items list:"); listItems(list); int result = -1; // 1....
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's cart. Items of Type T can be added * or removed from the cart. A hashmap is used to keep track of the number of items * that have been added to the cart example 2 apples or 4 shirts. * @author Your friendly CS Profs * @param -Type of items that will be placed in the Cart. */ public abstract class AbstractCart {...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public static void main(String[] args)    {        max_cards=45;        arr->new ArraryList        col=1;        card=0;        left=max_cards;        do{            col->random number            row->new ArrayList;            for i=0 to i<col            {                card++                add card into row            }   ...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT