Ans:
# the required class design is as follows:


# OUTPUT FOR THIS SAMPLE RUN!

# ANOTHER SAMPLE RUN:

# CORRESPONDING OUTPUT TO THE SAMPLE RUN:

# REQUIRED PROGRAM:
import random
class PlayStack:
def __init__(self):
self.cards = list()
def peekValue(self):
try:
card = self.cards[-1]
return card
except:
return "Error: No cards in the playing stack"
def peekFace(self):
try:
card = self.cards[-1]
return random.choice(["Heart","Spade","Club","Diamond"])
except:
return "Error: No cards in the playing stack"
def playCard(self,card):
try:
top = self.cards[-1]
if card == 9:
return self.__str__()
elif card == top + 1 and card > 0 and card < 9:
self.cards.append(card)
return "Appended Successfully"
elif card == 0:
return "Card 0 can only be added on an empty deck!"
else:
return "Error: Card {} rejected".format(card)
except:
if card == 9:
return self.__str__()
else:
self.cards.append(card)
return "Appended Successfully"
def __str__(self):
if len(self.cards) == 0:
return "[]"
else:
s = ""
for i in self.cards:
s += "[" + str(i) + "]"
return "|{}|".format(s)
# card object of class PlayStack
cards = PlayStack()
# testing the __str__ method on empty deck
print(cards)
# checking peekValue on empty deck
print(cards.peekValue())
# Inserting on empty deck
print(cards.playCard(0))
print(cards.peekValue())
print(cards.peekFace())
print(cards.playCard(1))
print(cards.playCard(2))
print(cards.playCard(3))
print(cards.playCard(5))
print(cards.playCard(9))
# PLEASE DO LIKE AND UPVOTE IF THIS WAS HELPFUL!
# THANK YOU SO MUCH IN ADVANCE!
Implement a class named PlayStack. An instance of this class should have a property cards, which...
Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that randomly shuffles the cards in the...
its about in C++
You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...
Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: "Spades", "Diamonds", "Hearts", "clubs" and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and...
Implement the EasyStack interface with the MyStack class. You can use either a linked list or a dynamic array to implement the data structure. A stack is a specialised form of list in which you can only get and remove the element most recently added to the stack. The class should be able to work with the following code: EasyStack stack = new MyStack(); NB: You cannot import anything from the standard library for this task. The data structure must...
A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...
JAVA --Design a class named StackOfStrings that contains: a. A private array elements to store strings in the stack b. A private data field size to store the number of strings in the stack c. A constructor to construct an empty stack with a default capacity of 4 d. A constructor to construct an empty stack with a specified capacity e. A method empty() that returns true if the stack is empty f. A method push(String value) that stores value...
IN JAVA - COMMENT CODE WELL Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that...
IN JAVA PLEASE Lab 28.1 Add a class named Purchase with: an instance (String) variable for the customer's name an instance (double) variable for the customer's balance a member method public String toString() that returns the object's instance variable data as a single String; e.g., Cathy has a balance of $100.00 Lab 28.2 Add a main class named Store; . Then, add code that: declares and creates an ArrayList of Purchase objects named purchases (make sure to add import java.util.ArrayList...
C# Only, implement (source code) a class called Counter. It should have one private instance variable representing the value of the counter. It should have two instance methods: increment() which adds on to the counter value and getValue() which returns the current value. After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head and Tails) to track the number of heads and tails.
The class "Deck" is defined for the initial deck of 52 cards. A simple list is used to store 52 poker cards. Consider the Deck class given as below: class Deck: def __init__(self, full=True): self.cards = [] cardlist = ['AS', 'AH', 'AC', 'AD', '2S', '2H', '2C', '2D', '3S', '3H', '3C', '3D', '4S', '4H', '4C', '4D', '5S', '5H', '5C', '5D', '6S', '6H', '6C', '6D', '7S', '7H','7C', '7D', '8S', '8H', '8C', '8D', '9S', '9H', '9C', '9D', 'TS', 'TH', 'TC', 'TD', 'JS', 'JH',...