Calculate and output the following statistics

Assignment Help Basic Computer Science
Reference no: EM13306787

In the game of War, two players battle each other to see who can win the most cards. At the start of a single game a deck of 52 cards (legal values 2-10,J,Q,K,A) is split evenly between the two players such that each player holds a stack of 26 random cards. For each battle of the game both players turn over the card at the top of their stack. The player with the higher-valued card takes both cards and places them on the bottom of their stack. If the two cards played are of equal value, each player lays down three face-down cards and a fourth card face-up (a "war"), and the higher-valued card wins all of the cards on the table, which are then added to the bottom of the player's stack. In the case of another tie, the war process is repeated until there is no tie.

A player wins by collecting all the cards. If a player runs out of cards while dealing the face-down cards of a war, he may play the last card in his deck as his face-up card and still have a chance to stay in the game. Once a single player holds all 52 cards, the game ends.

You are to write a program that takes the number of games, n, to play as a command line parameter (get passed in the String[] args parameter to main, not from standard input) and then simulates the n games. At the conclusion of all the games your program will calculate and output the following statistics:

Average number of battles per game

Average number of wars per game

Average number of double wars per game

Max number of battles in a game

Min number of battles in a game

Max number of wars in a game

Min number of wars in a game

Designing a Solution

As you can probably tell, this assignment is fairly involved. In fact, the only way you can pull it off is if you are smart about the abstractions you use and how you break your program into separate classes. It is recommended that you design the following classes in implementing your solution:

Card: A card consists of a value (low to highest: 2-10,J,Q,K,A) and a suit (hearts, spaces, clubs, diamonds). Provide appropriate constructors as well as accessor methods.

Deck: A new deck consists of all 52 cards in a array. It contains a method, deal, that removes a random card from the array and returns that card. (This can be achieved by generating a random number between 0 (inclusive) and the length of the array (exclusive) and removing/returning the card at that array position.

Player: A player consists of a number (1 or 2) and an array of owned cards. At the start of the game each player holds 26 unique cards. A method, flip, removes and returns the card at the front of the array. A method, collect, takes a card as a parameter and adds it to the array of owned cards. The player class should contain the appropriate constructors and other helper methods as required. For example, ahasWon method would return true if a player owned all 52 cards, and false otherwise, and a method, war, might handle the logic for breaking ties.

Game: A game consists of two players, as well as other instance variables for keeping track of the statistics for each game. A method, play, carries out the rules of the game of war until one of the players has won. This class should have a default constructor and accessor methods, as well as well as any other methods you feel are appropriate.

Simulation: This class contains a constructor that takes the number of games to simulate as well as a function, simulate, that plays the specified number of games. A method, calculate, computes the aggregate statistics from all games, which will require you to define the appropriate class member variables to keep track of the results of each game. Another method, report, prints the required statistics to the screen in a nicely-formatted manner. The main method for running your War program is contained in this class.

Reference no: EM13306787

Questions Cloud

Discuss the original purpose of the hawthorne studies : Discuss the original purpose of the Hawthorne studies as opposed to what they they ended up showing. make a list of points illustrated by the Hawthorne Studies.
Identify causal hypothesis at issue and investigation : Identify the causal hypothesis at issue. Identify what kind of investigation it is. There are control and experimental groups. State the difference in effect (or cause) between the control and experimental groups. State the conclusion that you think ..
Write a function in c language with prototype : write a function in C language with prototype.
Is this device a refrigerator or a heat engine : A cylinder contains 2 moles of an ideal monatomic gas that is initially at state A with a volume of 0.01 m^3 and a pressure of 4.0x10^5 Pa. Is this device a refrigerator or a heat engine
Calculate and output the following statistics : A player wins by collecting all the cards. If a player runs out of cards while dealing the face-down cards of a war, he may play the last card in his deck as his face-up card and still have a chance to stay in the game. Once a single player holds ..
What are the difficulties of moral relativism : Moral relativism is the belief that what is right or wrong may differ from group to group, or culture to culture. What are the difficulties of moral relativism?
Determine how far away are the cliffs : You are on a boat in a fog and know there are cliffs ahead of you somewhere, but you cannot see them. How far away are the cliffs
Identify the presumed cause and the presumed effect : In the example below, identify the presumed cause and the presumed effect. Does the example contain or imply a causal claim, a hypothesis, or an explanation that cannot be tested?
What is the diameter of the gravitron ride : During a ride on the gravitron, a person finds herself stuck against the wall as she spins around with a frequency of 26.00 rpm, What is the diameter of the gravitron ride

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write a java method to five a 10 percent raise to every

write a java method to five a 10 percent raise to every employee who has a student record and whose grade point index is higher than 3.0.

  Prove that the omega notation is reflexive and transitive

Prove that the omega notation is reflexive and transitive: for any functions f, g, h : N -> R?0, 1. f(n) ? ? (f(n)) 2. if f(n) ? ? (g(n)) Use the duality Rule!

  Describe how single-user system scheme works

Give a real-life example of a single-user system scheme, fixed partitions, dynamic partitions, and relocatable dynamic partitions. Describe how process works.

  How itdepartment helps organization achieve strategic goels

Discuss how the IT department helps the organization achieve their strategic goals

  Write a mips program to complete the following functions

Write a MIPS program to complete the following functions. You must write comments and follow the register convention. [30 points] (1) Declare an integer array of 20 elements and other variables and labels; [5]

  Explain why the files are not the same size

If three text files contained in Assignment 4 Files.zip each contain the same information; however, the file sizes are not the same. Explain why the files are not the same size

  Program to compute each semester tuition for each student

write a program to compute each semester the tuition for each student. Studient is taking 12 credit or less, tuition is 675 oer credit if student is taking more than 12 credits the total tuition is 6300.

  Explaining stepwise refinement and refactoring

Are stepwise refinement and refactoring the equivalent thing ? If not, describe how do they vary? Term component is sometimes a difficult one to define.

  Find whether bit string contains two consecutive one bits

You wish to find out whether bit string contains two consecutive 1 bits. Obviously, you can do this using n probes. For which values of n in range {3, 4, 5, 6, 7} can this be done using fewer than n probes?

  Cloud provider secure large amount of capital

Few organizations tend to prefer operating expense models. whether Cloud providers will continue to secure large amount of capital....or will equity firms stop their funding?

  Calculate and display the total retail value of all products

calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the application should stop looping display the final results.

  Write a query that will return the customer number

Write a query that will return the customer number

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd