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

Posted this program a few times and still no luck. Java oriented program this pr

ID: 3833577 • Letter: P

Question

Posted this program a few times and still no luck. Java oriented program 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

import java.awt.*; import java.awt.event.*; import java.applet.*; //////////////////////// // Defines a Link class // // used by LinkedList //////////////////////// class Link { private Object valueField; private Link nextLink; public Link (Object newValue, Link next) { valueField = newValue; nextLink = next; } // get Object part of link public Object value() { return valueField; } // get Link part of link public Link next() { return nextLink; } } ////////////////////////////// // Defines a LinkedList class // // used by CardPile ////////////////////////////// class LinkedList { private Link firstLink; public LinkedList() { firstLink = null; } // true if empty, false otherwise public boolean empty() { return firstLink == null; } // add an Object to our list public void add (Object newValue) { firstLink = new Link(newValue, firstLink); } // inspect front of list public Object front() { if (firstLink == null) return null; return firstLink.value(); } // pop front of list public Object pop() { if (firstLink == null) return null; Object result = firstLink.value(); firstLink = firstLink.next(); return result; } // return an iterator for the list public ListIterator iterator() { return new ListIterator(firstLink); } } //////////////////////////////// // Defines a ListIterator class // // used by LinkedList //////////////////////////////// class ListIterator { private Link currentLink; public ListIterator (Link firstLink) { currentLink = firstLink; } // true if we reached end of list, false otherwise public boolean atEnd() { return currentLink == null; } // move to next link public void next() { if (currentLink != null) currentLink = currentLink.next(); } // return value of current link public Object current() { if (currentLink == null) return null; return currentLink.value(); } } //////////////////////// // Defines a Card class // // used by CardPile //////////////////////// class Card { // data fields for colors and suits final static int width = 50; final static int height = 70; final static int red = 0; final static int black = 1; final static int heart = 0; final static int spade = 1; final static int diamond = 2; final static int club = 3; final static int ace = 0; final static int king = 12; private static String names[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; // data fields private boolean faceup; private int rank; private int suit; // constructor Card (int s, int r) { suit = s; rank = r; faceup = false; } // get rank of card as an int in the interval [0, 12] public int rank() { return rank; } // get suit of card as an int in the interval [0, 3] public int suit() { return suit; } // true if card is face up, false otherwise public boolean faceUp() { return faceup; } // change value of faceup public void flip() { faceup = ! faceup; } // true if card is ace, false otherwise public boolean isAce() { return rank == ace; } // true if card is king, false otherwise public boolean isKing() { return rank == king; } // return color of card as an int in the range [0,1] public int color() { if (suit() == heart || suit() == diamond) return red; return black; } // draw the card public void draw (Graphics g, int x, int y) { // clear rectangle, draw border g.clearRect(x, y, width, height); g.setColor(Color.black); g.drawRect(x, y, width, height); // draw body of card if (faceUp()) { if (color() == red) g.setColor(Color.red); else g.setColor(Color.black); g.drawString(names[rank()], x+3, y+15); if (suit() == heart) { g.drawLine(x+25, y+30, x+35, y+20); g.drawLine(x+35, y+20, x+45, y+30); g.drawLine(x+45, y+30, x+25, y+60); g.drawLine(x+25, y+60, x+5, y+30); g.drawLine(x+5, y+30, x+15, y+20); g.drawLine(x+15, y+20, x+25, y+30); } else if (suit() == spade) { g.drawLine(x+25, y+20, x+40, y+50); g.drawLine(x+40, y+50, x+10, y+50); g.drawLine(x+10, y+50, x+25, y+20); g.drawLine(x+23, y+45, x+20, y+60); g.drawLine(x+20, y+60, x+30, y+60); g.drawLine(x+30, y+60, x+27, y+45); } else if (suit() == diamond) { g.drawLine(x+25, y+20, x+40, y+40); g.drawLine(x+40, y+40, x+25, y+60); g.drawLine(x+25, y+60, x+10, y+40); g.drawLine(x+10, y+40, x+25, y+20); } else if (suit() == club) { g.drawOval(x+20, y+25, 10, 10); g.drawOval(x+25, y+35, 10, 10); g.drawOval(x+15, y+35, 10, 10); g.drawLine(x+23, y+45, x+20, y+55); g.drawLine(x+20, y+55, x+30, y+55); g.drawLine(x+30, y+55, x+27, y+45); } } else // face down { g.setColor(Color.yellow); g.drawLine(x+15, y+5, x+15, y+65); g.drawLine(x+35, y+5, x+35, y+65); g.drawLine(x+5, y+20, x+45, y+20); g.drawLine(x+5, y+35, x+45, y+35); g.drawLine(x+5, y+50, x+45, y+50); } } } ////////////////////////////////////// // Defines a CardPile class // // used as a base to build card piles ////////////////////////////////////// class CardPile { // coordinates of the card pile protected int x; protected int y; // linked list of cards protected LinkedList cardList; CardPile (int xl, int yl) { x = xl; y = yl; cardList = new LinkedList(); } ///////////////////////////////////// // access to cards are not overridden // true if pile is empty, false otherwise public final boolean empty() { return cardList.empty(); } // inspect card at the top of pile public final Card top() { return (Card)cardList.front(); } // pop card at the top of pile public final Card pop() { return (Card)cardList.pop(); } ///////////////////////////////////////// // the following are sometimes overridden // true if point falls inside pile, false otherwise public boolean includes (int tx, int ty) { return x
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