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...
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...
Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack class implementation, even if it is implemented by yourself, will not receive any credit). Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string. import java.util.Scanner; public class Evaluate { public static void main(String[] args) } // your implementation // obtain user's input from keyboard...
CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties an integer for the rank (1 (corresponding to Ace) ,2,3, 13 (correspond ing to King) and suit (Spades, Hearts, Diamonds, or Clubs). Make the suit an enumerated data type. Include getters and setters and a method that tests if a card is valid. Write a class named Deck whose instances are full...
In java Build a QueueInt class for integers that is compatible with the driver code below. The QueueInt should operate in a FIFO (first in, first out) fashion and implement the variables and methods also listed below: Data Members: Declare and initialize, as needed, the data item(s) you will need to manage a queue of integers. You may only use arrays and primitives for your instance and/or static variables (I,e You can’t use Java defined Queue / Stack / List...
Python Implement a class named BubbleStringList. In this class implement a method called add, that when given a string, it adds it to an internal list object. You can use the list object from the standard python library for the internal list. Next, implement a sort method that uses a BubbleSort to sort the list when called. Create another class called MergeStringList, that implements the same methods but uses a Merge Sort as the sorting algorithm. Create another class called...