Answer to Question #179479 in Java | JSP | JSF for Bill

Question #179479

Create one array “sign” of char type whose elements are 'H', 'D', 'S', and 'C'. Create one variable “n” of int type whose initial value is -1 and other variable named “i” of int type whose initial value is also -1. Create function named “pickCard()” of void type that randomly generate two integers. Limit first random number with range of 0 to 3,then assign randomly generated number to “i” variable. Limit second random number with range from 1 to 13, then assign the randomly generated number to “n” variable. Then, make sure “pickCard()” function can display one of “sign” array's values according to value assigned to “i” variable. Have “pickCard()” function display the value assigned to the “i” variable and meet all conditions specified in the following table


Value of i | Display

1 | A

11 | J

12 | Q

13 | K

Finally, use a while loop to call the “pickCard()” 5 times.


1
Expert's answer
2021-04-08T15:36:11-0400
import java.util.Random;

public class Main {
    private static char[] sign = {'H', 'D', 'S', 'C'};
    private static int i = -1;
    private static int n = -1;

    public static void pickCard() {
        Random random = new Random();
        i = random.nextInt(4);
        n = random.nextInt(13) + 1;
        System.out.println(n + "|" + sign[i]);
    }

    public static void main(String[] args) {
        int j = 0;
        System.out.println("Value of n|Display");
        while (j < 5) {
            pickCard();
            j++;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog