Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
ArrayList Deck of Cards(Java) - Powered by Portfolium Skip to Content more_vert Entries About Join & show your work View Network Help Show me All caret down All Activism & Service Art & Design Business Computer Science Culinary Arts Creative & Performance Education Engineering Science Math & Physics Marketing & Advertising Health Care Social Sciences Sports & Recreation Technology Travel Armed Forces Other Humanities Agriculture & Nat'l Resources Client Services Sorted By Recent caret down Recent Views Likes Comments Apply Cancel Florida International University Facebook Twitter LinkedIn Portfolios Florida International University Entries About Join & Showcase your work like Like ArrayList Deck of Cards(Java) By Javier Hernandez By Javier Hernandez ArrayList Deck of Cards(Java) Description: Published: May 14, 2020 favorite0 forum0 poll1.6K By: Javier Hernandez, Florida International University Category: Computer Science Hashtags: #Coding #JAVA ArrayLists I. The Assignment Card players typically like to keep the cards in their hand sorted by suit and within each suit by face value. Assuming that a hand consists of 13 cards, write a Java program to insert each card into an initially empty hand in the proper order, so that there is no need to sort the hand. The order of the suits is unimportant but within each suit the order of the cards should be 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A (i.e. the Ace is always the high card). II. The Card Class Begin by creating a class to model a playing card. The Card class will have two private instance variables: (1) the face value (aka: “rank”) stored as ints 2..14 and (2) the suit (Spades, Hearts, Diamonds, Clubs). Your Card class will have these methods: 1. a proper constructor that creates a Card with a given rank and suit 2. an accessor (“get”) method that returns the rank 3. an accessor (“get”) method that returns the suit 4. a toString method that returns a String representation of a card as shown in these examples: A♠, 10♣, 7♦, Q♥  To get the symbols for the suits, use the escape sequences for the Unicode characters: “\u2660” (Spade) “\u2663” (Club) “\u2665” (Heart) “\u2666” (Diamond) III. The Deck Class Create a class to model a standard 52-card deck. Your Deck class will have a private instance variable that is an ArrayList-of-Card. (You may have additional instance var’s although none are needed) Your Deck class will have these methods: 1. a proper constructor that creates a standard Deck of 52 cards 2. a method that deals the top card. I.e. returns the Card object on top of the Deck 3. a method that shuffles the deck. To get credit for this method you must use this algorithm: for each card in the deck exchange it with the card at a randomly-selected index (to “mix ‘em up good” you might want to shuffle the deck a number of times) IV. The Hand Class Create a class to model a hand of 13 Cards. Your Hand class will have a private instance variable that is an ArrayList-of-Card, and these methods: 1. a proper constructor that creates an empty Hand 2. a method to fill a Hand with 13 Cards dealt from a Deck, with each one being inserted in its proper place in the Hand 3. a toString method that returns a String representation of the Hand (Hint: call the Card class toString method for each Card in the Hand) V. The Test Class Your test class will have a main method that creates a Hand, calls the method that fills it, calls the toString method for the Hand, and prints the String returned. After each Hand is displayed, ask the user if she wants to see another. VI. Specifications 1. You must use a generic “ArrayList of Card” as the implementation of the Deck and the Hand  No credit will be given if any other data structures, including arrays, are used anywhere in the program 2. No credit for using any of the methods of Java’s Collections class (e.g. shuffle). Use the shuffle algorithm given above 3. Although the assignment calls for a Hand of 13 cards and a Deck of 52, you should “parameterize” your program by using defined constants for the number of cards in the Hand and in the Deck. That way, you can generate hands and decks of different sizes by changing only the constant declarations 4. As specified above, none of the methods of your Deck, Hand, and Card classes do any output. All output is to be done in main  Make sure your Deck, Hand, and Card classes all contain proper Java “documentation comments” and adhere to all the style and internal documentation standards discussed in class and covered in Unit 1 VII. Upload 2 Files to Canvas 1. A zip file of your NetBeans project folder 2. A Word doc with your name to receive feedback  Do not zip the individual java files; zip the project folder. Include a file containing the output of 3 hands. See the “Using NetBeans” doc, part XI for an easy way to include the output in the project VIII. Due Date – Tuesday, January 28th  You will receive two separate grades for this assignment – one for the program itself and one for the web pages created by Javadoc  To make sure you receive credit, review the “Submitting Your Assignments” and “Creating a Zip File” docs in the “Before Beginning” Unit online  Do not zip the project from within NetBeans! If you do, the zip will not contain the dist folder (where the html files are stored) and you will be unhappy with the grade Algorithm to Create the Sorted Hand Place the first card in the hand For each additional card, do the following: Get the suit If the card is of a suit that is not yet in the Hand Insert it as the new last card in the Hand Else, do the following: If the value is higher than all the cards of that suit Insert it as the new last card of that suit Else Insert it just before the first card of that suit with a higher value Optional Easier Algorithm to Create the Sorted Hand Create an ArrayList of Cards for each suit For each card, insert it in its proper place in the list for that suit, using the techniques described above Add each suit list to the Hand Hopefully Helpful Hints 1. Begin by creating all classes with method “stubs” only. A method stub is just the Javadoc comment, the method heading, and an empty body. If the method returns a value, use some temporary return value. This way, the entire program “skeleton” will compile and execute and you can fill in each method as you figure it out 2. Since the Hand class method fill is the most challenging, start with a temporary version that simply adds each card to the hand. That way, you can test and verify that all the other methods are correct – and have the majority of the credit “in the bank” – before turning your full attention to the full-blown fill 3. Hint: To enable your Hand class to seamlessly access the Deck, create a Deck object in your Hand cla Attachments: File TheCard.txt 2.0 KB File TheDeck.txt 4.4 KB File TheHand.txt 4.5 KB File TheTest.txt 1.4 KB Likers © 2022 • All content within this entry is strictly the property of Javier Hernandez, and is not for public use without permission. facebook twitter linkedin embed Compliments: Be the first to leave positive feedback below Leave positive feedback Close Powered by Portfolium View Network Help