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

Java Oriented Program I need a program that simulates playing clock solitaire. T

ID: 3829673 • Letter: J

Question

Java Oriented Program I need a program that simulates playing clock solitaire. This is how the game is played https://youtu.be/6AEJEf8L95g https://youtu.be/yUj320C9210

First required class is Card class that represents each of the 52 playing cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King … in each of the four suits: Spades, Hearts, Diamonds, and Clubs.

Implement the following methods: constructors getSuit() getValue() String toString(): to print cards ex: "10H" or "QC"

Also, create a deck class that represents a standard deck of 52 playing cards.

Implement the following methods: constructors, void shuffle(): randomly interchanges cards in the deck to simulate shuffling, 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.

Create a pile class that contains no more than 5 cards. Some cards are to be face up and some are to be faced down.

Implement the following methods:constructors, void addCardFaceDown( Card card), Card removeCard() - removes and returns the “top” face down card (null if there are none) and int getNumberOfFaceDown(), void addCardFaceUp( Card card), int getNumberOfFaceUp(), String toString() - print the cards in the Pile; print the contents of a pile on one or two lines; label the portion of the pile that’s face up versus face down .

Playing the Game

1.remove (top, face-down) card from Pile 13, the Kings Pile

2.add it, face-up, to the (“bottom” of the) correct Pile

a.also, keep track of and print the “step number,” a counter that you increment each time you “remove-and-add” a card

4.remove (top, face-down) card from that same Pile

a.one needs to check that there are face-down cards remaining

b.if there are no face-down cards remaining, the game is over, if you’re on Pile 13

c.(if there are no face-down cards remaining, and you’re not on Pile 13, then there’s an error)

5.repeat this process by going to step 2

When Each Game is Done

print the thirteen Piles -- the game board (as above), if the print level is not “silent”

print the “score”: the number of Piles with at least one face-down card, if the print level is not “silent”

                            a score of “zero” is a “win”; note this is rare

increment a counter in a Scores array for the number of Piles with at least one face-down card

repeat, from the top (the Setup), according to how many games to play, as specified in the command-line arguments

When You’ve Completed Playing the Required Number of Games

print the number of games played

print the Scores array, along with percentages, as follows; this will be 14 lines, with both the number and percentage of games that resulted in each score

Explanation / Answer

public class cardObject extends Main { private int X; private int Y; private int prevX; //previous valid X coord private int prevY; //previous valid Y coord private int index; private int rank; //card rank; graycard=0, ace =1 , king =13 private int suit; //spades=0 hearts=1 diamonds=2 clubs=3 graycard=4 private String rank_Suit_ID; //ID code, first two chars are rank, third char is suit private boolean originalPosition; //is the card in the original place that it was placed when a new game started private boolean showCardBackside= false;//for clock solitaire only /** * This is the constructor for a cardObject. * @param x This is the x value that specifies where the upper left corner of the card is currently located. * @param y This is the y value that specifies where the upper left corner of the card is currently located. * @param cardPicture This is the picture that will be drawn when the card is drawn to the screen. * @param cardIndex This value represents where the card is in the cardDeck[] array, which is declared in guiInterface. */ public cardObject(int x, int y,int cardRank,int cardSuit, int cardIndex) { setX(x); setY(y); setPrevX(x); setPrevY(y); setRankSuitID(cardRank, cardSuit); setCardRank(cardRank); setCardSuit(cardSuit); setCardIndex(cardIndex); setOriginalPositionValue(true); setShowCardBackside(false); } /** * Overloaded version of default constructor. This is for the xmlReader to use to load the card Data * @param x * @param y * @param newPrevX * @param newPrevY * @param cardPicture * @param cardRank * @param cardSuit * @param cardIndex */ public cardObject(int x, int y, int newPrevX, int newPrevY,int cardRank,int cardSuit, int cardIndex) { setX(x); setY(y); setPrevX(newPrevX); setPrevY(newPrevY); setRankSuitID(cardRank,cardSuit); setCardRank(cardRank); setCardSuit(cardSuit); setCardIndex(cardIndex); setOriginalPositionValue(true); setShowCardBackside(false); } /** * This method is used to set a new x value to the card. * @param newX The new x value that specifies where the upper left corner of the card is */ public void setX(int newX) { X = newX; } /** * This method is used to set a new y value to the card. * @param newY The new y value that specifies where the upper left corner of the card is */ public void setY(int newY) { Y = newY; } /** * This method sets the previous x value of a card object. This is the last valid card coordinate * @param x the coordinate X */ public void setPrevX(int x) { prevX=x; } /** * This method sets the previous y value for a card object. This is the last valid card coordinate * @param y The coordinate Y */ public void setPrevY(int y) { prevY= y; } public String setRankSuitID(int inputRank, int inputSuit) { String ID; if(rank < 10) { ID= "0" + inputRank + inputSuit; } else //if 10 or more { ID= "" + inputRank + inputSuit; } return ID; } /** * This method sets the card rank to a card object. * @param x The rank of the card */ public void setCardRank(int x) { rank= x; } /** * This method sets the card suit to a card object. * @param x The suit of the card; Spades=0, hearts=1, diamonds=2, clubs=3, greycard=4 */ public void setCardSuit(int x) { suit= x; } /** * This method is used to set the value of cardIndex for a card. * @param cardIndex The new index value that is to be set to the card. If this value is a negative number, the system will output to the command line an error message. */ public void setCardIndex(int cardIndex) { if(cardIndex < 0) { System.out.println("Error: negative card index"); System.out.println("Current index: " + getCardIndex()); System.out.println("Attempted to set index to: " + cardIndex); } else index= cardIndex; } public void setOriginalPositionValue(boolean inputValue) { originalPosition= inputValue; } public void setShowCardBackside(boolean input) { showCardBackside= input; } /** * This method retrieves the x value from the card object. * @return The X value of the card object, that specifies where the upper left corner of the card is located. */ public int getX() { return X; } /** * This method retrieves the y value from the card object. * @return The Y value of the card object, that specifies where the upper left corner of the card is located. */ public int getY() { return Y; } /** * This method returns the prevX value of the card object. * @return prevX */ public int getPrevX() { return prevX; } /** * This method returns the prevY value of a card object. * @return prevY */ public int getPrevY() { return prevY; } public String getRankSuitID() { return rank_Suit_ID; } /** * This method returns a card objects rank. * * @return rank The rank of the card object */ public int getCardRank() { return rank; } /** * This method returns a card objects suit * @return suit The suit of the card object */ public int getCardSuit() { return suit; } /** * This method retrieves the card index value for the card object. * @return The cardIndex value of the card object. */ public int getCardIndex() { return index; } public boolean getOriginalPositionValue() { return originalPosition; } public boolean getShowCardBacksideValue() { return showCardBackside; } /** * This method determines if an x and a y coordinate are inside the card object's drawn picture. * If the coordinates are inside the card object's drawn picture, it will return true. * If the coordinates are not inside the card object's drawn picture, it will return false. * @param x The x coordinate to be checked * @param y The y coordinate to be checked * @return true or false, depending on whether or not the coordinates provided are in the card object's picture or not. */ public boolean contains(int x, int y)//is the coordinates inside the area of this card { if((x > getX()) && x getY() && y
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