Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Posted this program a lot no luck. I need a java code. This program is a simulat

ID: 3833579 • Letter: P

Question

Posted this program a lot no luck. I need a java code. This program is a simulation of the clock solitaire game. This game only needs 4 classes. A card class is needed to represent each of the 52 playing cards.

Class.java: has to have constuctors, getSuit(), getValue() and String toString(): to print cards e.g., “10H” or “QD” .

Deck.java: that represents a standard deck of 52 playing cards. Methods to use constructors, void shuffle() which shuffles the deck of cards, Card dealCard(), int cardsLeft(), String toString(), iterate through your deck array, printing all the cards, in a way that’s convenient to check what cards are there; we think it’ll be best to print all the cards on one line

Pile.java: class that contains no more than five cards some are face down and some are faced up. Methods constructors, void addCardFaceDown( Card card), Card removeCard() removes and returns the "top" face down card (null if there are not any) int getNumberOfFaceDown(), void addCardFaceUp( Card card) int getNumberOfFaceUp() and String toString() print the cards in the on one or two lines; label the portion of the pile that’s face up versus face down.

Driver.java: where the game is executed. Print number of games played and how many games user won and percentage

You can use other methods that are not listed. The ones I have are needed if not it will be okay if simulation runs.

Thumbs up for a simulation that runs with 4 classes that I can run.

This is how the game is played https://youtu.be/6AEJEf8L95g https://youtu.be/yUj320C9210

Explanation / Answer

This is a big question. Adding three classes. Will do part 2 as well in another of your post.

Cards.java

public class Card {
String suite;
String value;
  
public Card(String suite, String value)
{
this.suite = suite;
this.value = value;
}
  
public Card(int card)
{
int v = card%13;
int s = card/13;
  
if(v == 0)
{
value = "A";
}
else if(v == 11)
{
value = "J";
}
else if(v == 12)
{
value = "Q";
}
else if(v == 13)
{
value = "K";
}
else
{
value = String.valueOf(v);
}
if (s == 0)
{
suite = "C";
}
else if(s == 1)
{
suite = "D";
}
else if(s == 2)
{
suite = "H";
}
else
{
suite = "S";
}
}
  
public String getSuite()
{
return suite;
}
  
public String getValue()
{
return value;
}
  
public String toString()
{
return value + suite;
}

}

Deck.java

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Deck {
  
private List<Card> cardList = new ArrayList<>();
private List<Card> dealtCard = new ArrayList<>();
private int cardsDealed;
public Deck()
{
for(int i = 0; i < 52; i++)
{
cardList.add(new Card(i));
}
cardsDealed = 0;
}
  
public void shuffle()
{
Collections.shuffle(cardList);
}
  
public Card dealCard()
{
if(cardList.size() <= 0)
return null;
Card c = cardList.get(0);
dealtCard.add(c);
cardList.remove(0);
return c;
}
  
int cardLeft()
{
return 52 - cardsDealed;
}
  
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("dealt: ");
for(Card c : dealtCard)
{
sb.append(c.toString()).append(" ");
}
sb.append(" ");
sb.append("Remaining: ");
for(Card c: cardList)
{
sb.append(c.toString()).append(" ");
}
sb.append(" ");
return sb.toString();
}

}

Pile.java

import java.util.ArrayList;
import java.util.List;

public class Pile {
  
private List<Card> faceDown = new ArrayList<>();
private List<Card> faceUp = new ArrayList<>();
  
public Pile(Deck deck)
{
for (int i = 0; i < 4; i++)
{
addCardFaceDown(deck.dealCard());
}
}
  
void addCardFaceDown( Card card)
{
faceDown.add(card);
}
  
Card removeCard()
{
if(faceDown.size() <= 0)
return null;
Card c = faceDown.get(0);
faceDown.remove(0);
return c;
}

int getNumberOfFaceDown()
{
return faceDown.size();
}
  
void addCardFaceUp( Card card)
{
faceUp.add(card);
}
  
int getNumberOfFaceUp()
{
return faceUp.size();
}
  
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("Facedown: ");
for(Card c: faceDown)
{
sb.append(c.toString()).append(" ");
}
sb.append(" ");
sb.append("Faceup: ");
for(Card c: faceUp)
{
sb.append(c.toString()).append(" ");
}
return sb.toString();
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote