purpose of this application is to create a multi-threaded application with one thread being a producer of playing cards and another thread being a consumer of playing cards.
the application will run with the welcome to war greeting :
here is an example of what it should look like .

The buffer will be based on the SynchronizedBuffer but will store a Card instead of an int.
The producer will produce a playing card having a random value of either 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Ace. The producer will put that randomly created card in the buffer. Afterward, the producer will sleep randomly between 1-4 seconds before producing another card.
The consumer will get 2 cards from the buffer. Once the consumer has 2 cards, it will use them to simulate the card game WAR. The consumer will compare the cards and print the winner. Afterward, the consumer will sleep randomly between 1-4 seconds before consuming cards and simulating the game again.
Both producer and consumer will run forever. This means the output of the game will never end – the game will play forever.
import java.util.LinkedList;
public class Threadexample
{
public static void main(String[] args)
throws InterruptedException
{
// Object of a class that has both produce()
// and consume() methods
final PC pc = new PC();
// Create producer thread
Thread t1 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
pc.produce();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
});
// Create consumer thread
Thread t2 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
pc.consume();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
});
// Start both threads
t1.start();
t2.start();
// t1 finishes before t2
t1.join();
t2.join();
}
// This class has a list, producer (adds items to list
// and consumber (removes items).
public static class PC
{
// Create a list shared by producer and consumer
// Size of list is 2.
LinkedList<Integer> list = new LinkedList<>();
int capacity = 2;
// Function called by producer thread
public void produce() throws InterruptedException
{
int value = 0;
while (true)
{
synchronized (this)
{
// producer thread waits while list
// is full
while (list.size()==capacity)
wait();
System.out.println("Producer produced-"
+ value);
// to insert the jobs in the list
list.add(value++);
// notifies the consumer thread that
// now it can start consuming
notify();
// makes the working of program easier
// to understand
Thread.sleep(1000);
}
}
}
// Function called by consumer thread
public void consume() throws InterruptedException
{
while (true)
{
synchronized (this)
{
// consumer thread waits while list
// is empty
while (list.size()==0)
wait();
//to retrive the ifrst job in the list
int val = list.removeFirst();
System.out.println("Consumer consumed-"
+ val);
// Wake up producer thread
notify();
// and sleep
Thread.sleep(1000);
}
}
}
}
}
Purpose of this application is to create a multi-threaded application with one thread being a pro...
In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a card’s value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the card’s value. You also created a PickTwoCards application that randomly selects two playing cards and displays their values. In that application, all card objects were arbitrarily assigned a suit represented by a single character, but...
Python 3.7 Card Game: In this assignment you will be creating ‘card game’ with specific rules. Rules of the game are fairly simple. The game will be played with 3 players, two AI players and 1 Human player. Rules of the game: 1- Will have 3 players (2 AI, and 1 Human player). 2- The cards we have for this game is three ones (1), three twos (2), and three three’s (3). 3- Need to shuffle the cards randomly so...
The question is to make the game of war using Python. The information on how the cards will be represented and how the game will be played along with 2 sample runs is below. Representation of the deck of cards: The deck of cards will be simulated with integers of values from 1 to 13, where 1 represents the Ace, 11 the Jack, 12 the Queen, and 13 the King – these integers also represent the face values of the...
1.A fair six-sided die is rolled. {1, 2, 3, 4, 5, 6} Let event A = the outcome is greater than 4. Let event B = the outcome is an even number. Find P(A|B). A.0 B.1/3 C.2/3 C.3/3 2.A student stays at home. Let event N = the student watches Netflix. Let event Y = the student watches the very educational youtube videos made by her/his instructor.Suppose P(N) = 0.1, P(Y) = 0.8, and P(N and Y) = 0. Are N and...
MasterMind in Java
Activity
MasterMind project
Create a new Java Application project named MasterMind
allowing Netbeans IDE to create the main class called
MasterMind.java
MasterMind class
Method main() should:
Call static method System.out.println() and result in
displaying “Welcome to MasterMind!”
Call static method JOptionPane.showMessageDialog(arg1, arg2)
and result in displaying a message dialog displaying “Let’s Play
MasterMind!”
Instantiate an instance of class Game()
constants
Create package
Constants class
Create class Constants
Create constants by declaring them as “public static final”:
public...
C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...
Java FX Application
Purpose
The purpose of this assignment is to get you familiar with the
basics of the JavaFX GUI interface components. This assignment will
cover Labels, Fonts, Basic Images, and Layouts. You will use a
StackPane and a BorderPane to construct the layout to the right. In
addition you will use the Random class to randomly load an image
when the application loads
Introduction
The application sets the root layout to a BorderPane. The
BorderPane can be divided...
Please to indent and follow structure!!!!!
Assignment 3 - The card game: War Due Date: June 9th, 2018 @
23:55
Percentage overall grade: 5% Penalties: No late assignments
allowed
Maximum Marks: 10
Pedagogical Goal: Refresher of Python and hands-on experience
with algorithm coding, input validation, exceptions, file reading,
Queues, and data structures with encapsulation.
The card game War is a card game that is played with a deck of
52 cards. The goal is to be the first player to...
For this assignment you will create a one-player variation of the game BlackJack. The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game...
I need a basic program in C to modify my program with
the following instructions:
Create a program in C that will:
Add an option 4 to your menu for "Play Bingo"
-read in a bingo call (e,g, B6, I17, G57, G65)
-checks to see if the bingo call read in is valid (i.e., G65 is
not valid)
-marks all the boards that have the bingo call
-checks to see if there is a winner, for our purposes winning
means...