Answer to Question #179808 in Java | JSP | JSF for Phil

Question #179808

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, n, variable. Have pickCard() function display the value assigned to the “i” variable and meet all conditions specified in the following table:


Value of i = 1, Display = A

Value of i = 11, Display = J

Value of i = 12, Display = Q

Value of i = 13, Display = K

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



1
Expert's answer
2021-04-10T08:29:23-0400


public class TaskArray {


	public static void main(String[] args) {
		
		char[] sign = { 'A', 'J', 'D', 'K' };
		int n = -1;
		int i = -1;
		int k = 0;
		while (k < 5) {
			pickCard(i, n, sign);
			k++;
		}


	}


	public static void pickCard(int i, int n, char[] sign) {
		int firstRandomNumber = (int) (Math.random() * 3);
		i = firstRandomNumber;
		for (int j = 0; j < sign.length; j++) {
			int secodRandomNumber = (int) (1 + Math.random() * 13);
			n = secodRandomNumber;
			System.out.println(" Value of i =" + n);
			System.out.println(" Display =" + sign[j]);
			System.out.println();
		}


	}
}

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