首页 > > 详细

COMP1721作业代做、java编程设计作业调试、java语言作业代做、data作业代写 调试Web开发|代做留学生Processing

COMP1721 Object-Oriented Programming
Coursework 2
1 Introduction
Your main task is to write some classes that could be used in simulations of the game of five-card draw
poker, along with a program that estimates the probabilities of being dealt different types of poker hand.
You may find that the following Wikipedia pages are helpful in understanding the task and judging whether
your program is behaving correctly:
https://en.wikipedia.org/wiki/Five-card_draw
https://en.wikipedia.org/wiki/List_of_poker_hands
https://en.wikipedia.org/wiki/Poker_probability
As in Coursework 1, there are three different levels of solution: basic, full and advanced. We have provided
you with three classes that should be used as the basis for the basic and full solutions. We have also given
you some additional code that will be helpful if you decide to tackle the advanced solution.
There are 50 marks available for this assignment. Half of these marks are awarded for implementations of
two classes that pass the tests. The remaining marks are awarded for the programs that use these classes and
for aspects such as effective use of Java, coding style and commenting of classes, proper submission and use
of Git (see Section 8).
This assignment contributes 25% to your overall module grade.
2 Preparation
It is important that you follow the instructions below precisely. We strongly recommend that you perform
these steps in a Linux environment.
Please remember that, although the use of Windows is possible, we cannot offer any support if you
encounter problems. Also, the submission process won’t work on Windows machines.
1. Download cwk2-files.zip from Minerva. Put this file in the top level of your repository—i.e.,
the directory containing the cwk1, cwk2 and exercises subdirectories.
2. Open a terminal window in the top level directory of your repository and unzip the Zip archive with
the command unzip cwk2-files.zip. If you are asked whether you wish to overwrite a README
file, say yes.
3. Make sure that you have the following files and subdirectories visible in cwk2:
README-jfx.html build.gradle gradlew
README-jfx.md config/ gradlew.bat
README.html core/ jdk8-gradle.properties
README.md display/ settings.gradle
advanced/ game/ stats/
animate/ gradle/
IMPORTANT: Make sure that this is exactly what you see! For example, you should not have a
subdirectory of cwk2 that is itself named cwk2. Fix any problems with the directory structure before
proceeding any further.
4. Remove cwk2-files.zip. Use Git to add and commit the new files, then push your commit up to
gitlab.com. The following commands, executed in the terminal at the top level of your repository, will
achieve all of this:
git add cwk2
git commit -m "Initial files for Coursework 2"
git push origin master
1
3 Classes Provided
You are provided with three classes, which should be used in your solution:
• Card, representing a single playing card
• CardCollection, representing a collection of playing cards
• CardException, representing errors that can occur in code that manipulates playing cards
Implementations of the classes can be found in core/src/main/java/comp1721/cwk2. Take some time
to study this code. Note that you are not allowed to make any changes to these three classes when
implementing your solution. We will check for this when marking!
You will need to create two new classes:
• Deck, representing a standard deck of playing cards
• PokerHand, representing a hand of cards in a game of five-card draw poker
Before you begin implementing these classes, think carefully about the best way of reusing the code
that we have provided.
4 Basic Solution
4.1 Deck and PokerHand
Requirements for these two classes are described below. Both of them should first be implemented in
skeleton form, containing the minimal amount of code that will allow the tests to compile and run.
That way, you can use the tests to guide you towards correct implementations of the classes.
Minimum requirements for the Deck class are:
• A default constructor that creates a deck containing the standard 52 playing cards, arranged by suits
and then in rank order.
• A size method that returns the number of cards in the deck.
• An isEmpty method that returns true if the deck is empty of cards, false otherwise.
• A contains method with a Card parameter that returns true if the deck contains the specified card,
false otherwise.
• A discard method that empties the deck of all its cards.
• A deal method that removes the first card in the deck and returns it.
• A shuffle method that rearranges cards in the deck randomly.
Unless otherwise stated above, these methods have no parameters and return nothing. Note that the shuffle
method can be implemented very simply using the Java API (see the Collections utility class).
Minimum requirements for PokerHand are:
• A default constructor that creates an empty hand.
• A constructor with a String parameter that specifies the cards that should be added to the hand, using
two-character abbreviations for the cards. For example, an argument of "2D JC" should result in the
Two of Diamonds and Jack of Clubs being added to the hand.
• A toString method, overriding the default version, which returns a string in which cards are shown
in two-character form, separated by spaces—e.g., "2D JC 7H".
• Methods size and discard, which behave just like the corresponding methods of Deck.
• Method discardTo, with a Deck parameter, which empties the hand of cards and returns each of them
to the specified deck.
PokerHand will also need predicate methods that each return a boolean value to indicate whether a hand
is one of the specific types of hand in poker:
2
isPair isFullHouse
isTwoPairs isFlush
isThreeOfAKind isStraight
isFourOfAKind
At this stage, you should create all of these as stub methods that return false, so that the tests compile. You
can run all the tests with
./gradlew :core:test
You should write doc comments for the Deck and PokerHand classes, describing what each class represents
and identifying you as the author. You should also write doc comments for each public method in the
two classes. See the provided classes for examples of how to write doc comments, and read the article at
https://oracle.com/technetwork/java/javase/documentation/index-137868.html
You can generate HTML documentation from doc comments with
./gradlew :core:javadoc
Documentation will appear in core/build/docs/javadoc. Open index.html in a browser to check that
your doc comments have rendered sensibly.
4.2 Program
Edit the file PokerStats.java, in stats/src/main/java/comp1721/cwk2. In this file, create a class
named PokerStats, containing a program that
1. Creates and shuffles a deck
2. Deals five cards from the deck to a hand
3. Displays the contents of the hand
Run the program like this:
./gradlew :stats:run
5 Full Solution
5.1 PokerHand
To complete PokerHand, implement each of the predicate methods isPair, isTwoPairs, isFullHouse, etc,
so that they return true when appropriate. If you need guidance on why the test for a particular predicate
method is failing, examine the test implementation in Full.java. You’ll find this file in the directory
core/src/test/java/comp1721/cwk2.
5.2 Program
Edit PokerStats.java and modify it so that accepts 1 or 2 command line arguments. The first is the name
of a log file that will be generated by the program and the second is the number of trials that the program
will perform. If no second argument is supplied, the number of trials should default to 1,000. If there are
no command line arguments, or more than two have been supplied, the program should terminate with an
appopriate error message.
A single trial involves the following steps:
1. Create and shuffle a deck
2. Deal ten different five-card poker hands from the deck
3. Count occurrences of the different hand types (Pair, Three of a Kind, etc)
4. Write one line to the log file for each hand dealt, showing its cards and indicating its type
3
After performing the required number of trials, the program should use the accumulated counts to estimate
the probabilities of occurrence of each of the special hands. The results should be displayed in the terminal
window, with a format similar to the example in Figure 1. Note that the probabilities should be shown as
percentages.
50,000 hands dealt
P(Pair) = 42.100%
P(Two Pair) = 4.676%
P(Three of a Kind) = 2.174%
P(Straight) = 0.388%
P(Flush) = 0.190%
P(Full House) = 0.170%
P(Four of a Kind) = 0.028%
Figure 1: Example of terminal output from PokerStats
The output in the log file should be formatted in a similar way to the example in Figure 2. (Note that using
the fancy Unicode symbols for the card suits is not compulsory.)
Figure 2: Example of log file output from PokerStats
6 Advanced Task
This task is significantly more challenging and will require you to do some additional research. Also,
it is worth only 6 marks. You should attempt it only if you manage to complete the basic and full
solutions fairly quickly and easily.
As in Coursework 1, the task involves the use of JavaFX. You should be able to use either your own PC or
the SoC Linux machines to do it. Follow the instructions in the README-jfx file to configure your chosen
environment for use of JavaFX.
Next, study the code we’ve provided to help you. The class FancyCard represents a playing card that can be
displayed in a JavaFX application. You’ll find the code for it under the advanced directory. There are also
two demo applications, DisplayDeck and AnimateCard, which you’ll find under the display and animate
directories. You can run these demos with
./gradlew :display:run
./gradlew :animate:run
Now for the programming. Under the game directory, implement a JavaFX application named PokerGame.
This application should use the classes we’ve provided and those that you’ve implemented to play a simplified
round of five-card draw poker. The application should show cards being dealt to two different hands,
4
animating the process in an interesting way. It should also display the type of each hand. It should then
determine which is the winning hand and display this information in some way.
You can compile and run the program with
./gradlew :game:run
You may find it helpful to consult the following resources:
• Chapter 6 and Chapter 13 of Eck’s Introduction to Programming Using Java
• Oracle’s JavaFX documentation
• JavaFX API details
7 Submission
There is a README file at the top level of your repository, explaining the submission process. You can
open the local copy of this file to read it, or you can read the rendered version of the file on your repository’s
home page on gitlab.com.
Follow the instructions in the README carefully. You will not be able to use Windows for this process.
Remember to submit cwk2.zip via the link provided in Minerva.
The deadline for submissions is 10 am on Thursday 28 April 2020. The standard university penalty of 5%
of available marks per day will apply to late work, unless an extension has been arranged due to genuine
extenuating circumstances.
Note that all submissions will be subject to automated plagiarism checking.
8 Marking
Marks for this assignment are assigned as follows:
16 Tests for basic solution
9 Tests for full solution
7 PokerStats program (max of 2 for basic version)
6 PokerGame program for advanced solution
5 Effective use of Java
5 Coding style and doc comments in classes
2 Correct submission and use of Git
50
5

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp2
© 2014 www.7daixie.com
程序代写网!