Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Need help writing this java program here are the directions/explanation:

Your task is to write a program that plays a simple card game with one human player and one computer player. The game uses a deck of 52 cards. Each card has a value (either a number 2 through 10 or a label jack, queen, king, or ace) and a suit (hearts, diamonds, clubs or spades).

The objective of the game is to get four cards with the same value. For example, the 8 of hearts, diamonds, clubs and spades.

At the beginning of the game, the cards are shuffled and each player is given four cards. The remaining cards are placed into a queue called the "draw pile." There is another pile called the "discard pile" that starts out empty. The discard pile is a stack (an ArrayDeque in Java).

If neither player has been dealt a winning hand, the players take turns until one of them wins. At each turn the player can either draw a new card from the draw pile or pick up the top card on the discard pile. In this game the human player always goes first.

Because the discard pile starts out empty, the human player must initially pick up a card from the draw pile. After that, the human player must select a card to put into the discard pile.

This can either be the card he drew or one that was already in his hand. If the human player now has four cards with the same value, he wins. Otherwise, it is the computer's turn. The computer can either draw a card from the draw pile or pick up the card that the human player put onto the discard pile.

Then the computer player must place one of its cards onto the discard pile. If the computer player now has four cards with the same value, it wins. Otherwise, it is the human player's turn; however, this time the human player can either take a card from the draw pile or pick up the card that the computer player put onto the discard pile.

This process repeats until one player wins. At that point, the game should display the message "You win!" if the human player won or "I win!" if the computer player won. The program should then terminate. An example execution of this game is shown in the program output below

here is what the output should look like:

Your cards are:

Queen of Hearts

Seven of Hearts

Eight of Hearts

Seven of Diamonds

The discard pile is currently empty -- you must draw a card

You drew the Five of Spades

Now your cards are:

1. Queen of Hearts

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Five of Spades

Which one do you want to discard?

1 I will draw a new card.

I will discard the Two of Spades

Your cards are:

Five of Spades

Seven of Hearts

Eight of Hearts

Seven of Diamonds

The top card in the discard pile is the Two of Spades

Do you want to pick up the Two of Spades (1) or draw a card (2)?

2

You drew the Queen of Diamonds

Now your cards are:

1. Five of Spades

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Queen of Diamonds

Which one do you want to discard?

1

I will pick up the Five of Spades

I will discard the Six of Diamonds

Your cards are:

Queen of Diamonds

Seven of Hearts

Eight of Hearts

Seven of Diamonds

The top card in the discard pile is the Six of Diamonds

Do you want to pick up the Six of Diamonds (1) or draw a card (2)?

2

You drew the Five of Diamonds Now your cards are:

1. Queen of Diamonds

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Five of Diamonds Which one do you want to discard?

1

I will draw a new card.

I will discard the King of Spades

Your cards are:

Five of Diamonds

Seven of Hearts

Eight of Hearts

Seven of Diamonds

The top card in the discard pile is the King of Spades

Do you want to pick up the King of Spades (1) or draw a card (2)?

2

You drew the Nine of Diamonds Now your cards are:

1. Five of Diamonds

2. Seven of Hearts

3. Eight of Hearts

4. Seven of Diamonds

5. Nine of Diamonds

Which one do you want to discard?

5

Your program will be graded according to this rubric (each item is worth one point):

• The program creates the deck of cards, shuffles it, and gives each player four cards.

• The human player is notified what card is on top of the discard pile (which is implemented as a stack), and he can either take that card or draw a card from the draw pile (which is implemented as a queue).

• The human player can discard either a card that was already in his hand or the card he just acquired during his turn. This card is then placed on top of the discard pile.

• The computer player is capable of both taking a card from the draw pile or picking up the card on top of the discard pile, and it does not do the same thing every time. It may choose which to do either randomly or according to some strategy, whichever you prefer.

• The computer player does not always discard the same card every time (i.e. it doesn't always discard the card it just picked up). It may choose which card to discard randomly or according to some strategy, whichever you prefer.

• If the draw pile becomes empty before either player has won the game, all of the cards in the discard pile are shuffled and moved back to the draw pile.

• The program correctly recognizes when someone wins and displays the appropriate message.

Java, Programming

  • Category:- Java
  • Reference No.:- M93067675

Have any Question?


Related Questions in Java

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As