Question
Picking 4 Cards Write a program that picks four cards from a deck of 52 cards and compute their sum. An Ace, King, Queen, Jack
Picking 4 Cards
Write a program that picks four cards from a deck of 52 cards and compute their sum. An Ace, King, Queen, Jack represent 1,13,12,11, respectively. Your program needs to ask the user for the sum, find the number of the total combinations, the number of the combinations that yields the sum, and the list of all the combinations that yields the sum.
***********************************************************************************************************************************************************************************************************
OUTLINE:
// Header
// Header
// Header
import java.util.Scanner;
public class Cards {
// Main method, do not add anything
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
sum(kb);
}
// Initialize the deck then loop while
// the user wants to continue:
// ask for a sum using the validation method
// loop through every possible selection of 4 cards
// if the sum of the 4 chosen equals the sum desired then update
your counter and output combination
// update the counter for the total number of combinations
public static void sum(Scanner kb)
{
// Initialize Variables (including deck of cards)
// Loop while player wishes to continue
// Use the validation method to prompt for the sum
// Loop through possible combinations (Hint: Use 4 nested for
loops)
// If sum matches then update the counter and output
combination
// Update total combination counter
// Output final results and prompt to continue
// If they do not want to continue the set the boolean variable
for continuing to false
}
// Prompt the user to input the sum of combinations desired. Use the
hasNextInt() method
// to ensure that they are entering a number. Also, continue to loop
until they have entered
// a positive number.
public static int dataValidation(Scanner kb)
{
return 0; // remove 0 and put your variable for the valid input
}
// Create and return a 1-dimensional array for all 52 cards. Note that
// you can don this in one line using the "quick" initialization syntax
// for arrays. Also, do not worry about the suits, just add the numbers
to the array.
// This means that an Ace of Hearts is the same as an Ace of Spades,
they are both 1
// so you will have 4 of each number in the array.
public static int[] initialize( )
{
return null; // remove "null" and put your new array variable
instead
}
}
Here is the sample output Enter the sum of the combinations that you want:52 Here is the list of all the combinations: 13 13 13 13 Total number of combinations: 270725 The number of picks that yields the sum of 52 is 1 Do you want to continue: yes Enter the sum of the combinations that you want: fgg Enter the sum of the combinations that you want: dfgg Enter the sum of the combinations that you want: dffg Enter the sum of the combinations that you want: fdgfg Enter the sum of the combinations that you want: -45 Enter the sum of the combinations that you want: 51 Here is the list of all the combinations: 12 13 13 13 12 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 12 13 13 12 13 13 13 13 12 13 12 13 13 13 13 12 13 13 13 13 12 13 Total number of combinations: 270725 The number of picks that yields the sum of 51 is 16 Do you want to continue: no Here is the sample output Enter the sum of the combinations that you want:52 Here is the list of all the combinations: 13 13 13 13 Total number of combinations: 270725 The number of picks that yields the sum of 52 is 1 Do you want to continue: yes Enter the sum of the combinations that you want: fgg Enter the sum of the combinations that you want: dfgg Enter the sum of the combinations that you want: dffg Enter the sum of the combinations that you want: fdgfg Enter the sum of the combinations that you want: -45 Enter the sum of the combinations that you want: 51 Here is the list of all the combinations: 12 13 13 13 12 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 13 12 13 13 13 13 12 13 13 12 13 13 12 13 13 13 13 12 13 12 13 13 13 13 12 13 13 13 13 12 13 Total number of combinations: 270725 The number of picks that yields the sum of 51 is 16 Do you want to continue: noStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started