Part 2: Playing Cards using Selection Statements Objective: The purpose of this exercise is to give...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Part 2: Playing Cards using Selection Statements Objective: The purpose of this exercise is to give you practice using if/selection statements and the Math class. Scenario: You are a magician and you are practicing your card tricks. Since you don't want to reveal your secrets, you write a program that will pick a random card from the deck so you can practice your tricks alone. Use a random number generator to select a number from 0 to 51 (inclusive). Each number represents one card, and the suits are grouped: Cards 0-12 represent the diamonds, 13-25 represent the clubs, then hearts, then spades. In all suits, card identities ascend in step with the card number: 13 is the ace of clubs, 14 is the 2 of clubs, and 25 is the king of clubs. Follow the steps below to write your java program. 1. Write your java code in a program called card.java 2. Generate a random number cardNumber using Java Math class. Note that we do not need to import the Math class like we do with Scanner. (See note below (Recall) step 6, to see how to use the random class for this assignment) 1. Note that you will generate a random number between 0 and 51 3. Declare two String variables: a String corresponding to the name of the suit and a String corresponding to the identity of the card (String suitName, cardIdentity;). String is the Java type for text. String variables may be assigned any text and the text should be included between double quotations (suitName = "clubs"; for example) 4. Determine the suit name by using integer divide. (cardNumber / 13) 1. Cards 0-12 represent the diamond 2. 13-25 represent clubs, 3. 26-38 represents hearts 4. Determine the suit name by using integer divide. (cardNumber / 13) 1. Cards 0-12 represent the diamond 2. 13-25 represent clubs, 3. 26-38 represents hearts 4. 39-51 represents spades 5. Use if statements to assign the suit name. 6. Add one to cardNumber, and use the modulus operation to determine the card identity as follows: ((cardNumber+1) % 13) 1. 0 = King 2. 1 Ace = 3. 2-10 is the identity 4. 11 = Jack 5. 12 = Queen 7. Use a switch statement to assign the card identity. 8. Print out the name of the randomly selected card. 9. Make sure your code is properly commented and you use good style (camelCase, proper indentation, etc). Examples of Random Numbers: Random Number = 51 (CardNumber) 51/13 = 4 Suit is Spade (SuitName) 52 % 13 = 0 Identity is King (Card Identity) King of Spades Random number 24 (CardNumber) 24/13 = 1 Suit is Clubs (SuitName) 25 % 13 = 12 Identity is Queen (Card Identity) Queen of Clubs Here are four sample runs of the program. (Your program need only generate one card for a single run.) You picked the 6 of Clubs You picked the Jack of Hearts You picked the Ace of Spades You picked the 4 of Diamonds Part 2: Playing Cards using Selection Statements Objective: The purpose of this exercise is to give you practice using if/selection statements and the Math class. Scenario: You are a magician and you are practicing your card tricks. Since you don't want to reveal your secrets, you write a program that will pick a random card from the deck so you can practice your tricks alone. Use a random number generator to select a number from 0 to 51 (inclusive). Each number represents one card, and the suits are grouped: Cards 0-12 represent the diamonds, 13-25 represent the clubs, then hearts, then spades. In all suits, card identities ascend in step with the card number: 13 is the ace of clubs, 14 is the 2 of clubs, and 25 is the king of clubs. Follow the steps below to write your java program. 1. Write your java code in a program called card.java 2. Generate a random number cardNumber using Java Math class. Note that we do not need to import the Math class like we do with Scanner. (See note below (Recall) step 6, to see how to use the random class for this assignment) 1. Note that you will generate a random number between 0 and 51 3. Declare two String variables: a String corresponding to the name of the suit and a String corresponding to the identity of the card (String suitName, cardIdentity;). String is the Java type for text. String variables may be assigned any text and the text should be included between double quotations (suitName = "clubs"; for example) 4. Determine the suit name by using integer divide. (cardNumber / 13) 1. Cards 0-12 represent the diamond 2. 13-25 represent clubs, 3. 26-38 represents hearts 4. Determine the suit name by using integer divide. (cardNumber / 13) 1. Cards 0-12 represent the diamond 2. 13-25 represent clubs, 3. 26-38 represents hearts 4. 39-51 represents spades 5. Use if statements to assign the suit name. 6. Add one to cardNumber, and use the modulus operation to determine the card identity as follows: ((cardNumber+1) % 13) 1. 0 = King 2. 1 Ace = 3. 2-10 is the identity 4. 11 = Jack 5. 12 = Queen 7. Use a switch statement to assign the card identity. 8. Print out the name of the randomly selected card. 9. Make sure your code is properly commented and you use good style (camelCase, proper indentation, etc). Examples of Random Numbers: Random Number = 51 (CardNumber) 51/13 = 4 Suit is Spade (SuitName) 52 % 13 = 0 Identity is King (Card Identity) King of Spades Random number 24 (CardNumber) 24/13 = 1 Suit is Clubs (SuitName) 25 % 13 = 12 Identity is Queen (Card Identity) Queen of Clubs Here are four sample runs of the program. (Your program need only generate one card for a single run.) You picked the 6 of Clubs You picked the Jack of Hearts You picked the Ace of Spades You picked the 4 of Diamonds
Expert Answer:
Answer rating: 100% (QA)
public class Card public static void mainString args Step 2 Generate a random number between 0 and 5... View the full answer
Related Book For
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel
Posted Date:
Students also viewed these programming questions
-
The purpose of this exercise is to give you an opportunity to create the tables for Bearcat Incorporated. The tables themselves are based on the relations that appear in the following figure. L1:...
-
What are your thoughts about starting out too large to maintain stability, as opposed to starting small and then growing? Purpose: Organization design refers to the overall set of elements used to...
-
Discuss three quotes from the YouTube video (put time stamps after you type the quote) and explain why chose this quote. https://youtu.be/h86MGjGAtYk?si=_1hMyOefl0L3E4ox Example: Radio is "still...
-
Outdoor Experience Ltd. uses a perpetual inventory system and has a beginning inventory, as at June 1, of 200 tents. This consists of 50 tents at a cost of $200 and 150 tents at a cost of $225....
-
In Exercises 1924, write an equation in slope-intercept form of a linear function f whose graph satisfies the given conditions. The graph of f is perpendicular to the line whose equation is 4x - y -...
-
Briefly discuss the strengths and limitations associated with this approach and the specific design . Develop a hypothetical research scenario that would necessitate the use of the Action Research...
-
Waters Corporation purchased Johnson Company 3 years ago and at that time recorded goodwill of $400,000. The Johnson Divisions net assets, including the goodwill , have a carrying amount of $800,000....
-
(20%) The output of an argon ion laser can consist of a number of modes of frequency that match the cavity resonance condition and are within the gain bandwidth of the lasing transition. Assume the...
-
The incline angle is slowly increased. Determine the maximum angle that the incline can make with the horizontal so that the box just remains at rest.
-
Children in middle childhood begin to value the input of peers and are concerned with making friends and being well liked by others. Unfortunately, not all children move through this period easily;...
-
cover letter Have strong IT background with 1.5+ years of experience in Windows OS-7/8/10, iOS, macOS- Sierra/High Sierra/Mojave/Catalina/Big Sur/Monterey * Extensive knowledge of incident...
-
Li is a software engineer in a start-up company based in Chicago, IL. This is his second job after college, and he has been working there for two years. Before this job, he worked as a software...
-
Organized this essay in advance grammar and check all the punctuations and ideas. Pirated or unlicensed software is not new in the Philippines. Yes, the Philippines have laws but the question is, is...
-
From this case; BLEWMINDS: LEVERAGING INFLUENCER COMMUNICATION STRATEGIES https://www.coursehero.com/file/178763282/Leveraging-Influencer-Communication-Strategiespdf/ what are two overall issues
-
Prior to 35 weeks' gestation, uie L/S ratio is usually: a. Less than 1.6 b. Less than 1 c. More than 2 d. Less than 2
-
You continue to work in the corporate office for a nationwide convenience store franchise that operates nearly 10,000 stores. The per- store daily customer count (i.e., the mean number of customers...
-
What is the difference between a base entity type and a weak entity type?
-
Consider the instance of the relation SHIRT (Shirt#, Color, Size) where Shirt# is equivalent to a style number (e.g., style number 341 might be a shirt with a button-down collar while style number...
-
What must be done to develop a Design-Specific ER model from a Presentation Layer ER model?
-
Verify the color SU(3) representations for combinations of three or fewer quarks and antiquarks given in Eq. (19.28). Data from Eq. 19.28 qq=303=108 qq 3 3 603, 999 3 3 3 = 36315, qqq 3 3 3 1088 10,
-
Prove that Eq. (19.34) gives the simplest multi-gluon and gluon-quark states that contain an \(\mathrm{SU}(3)\) color singlet in the decomposition. Data from Eq. 19.34 (GG)1: (88)1 (Gqq) : [8 (383)8]...
-
A textile manufacturer is concerned about the strength of cotton yarn. In order to nd out whether fiber length is an important factor in determining the strength of yarn, the quality control manager...
Study smarter with the SolutionInn App