import java.util.Random; import java.util.Scanner; public class Fubar { public s
ID: 3624188 • Letter: I
Question
import java.util.Random;import java.util.Scanner;
public class Fubar {
public static void main(String[] args)
{
Random rgen = new Random();
displayIdentifyingInformation();
//====================================================================
String[][] cards =
{
{" r1 ", " r2"," r3 "," r4 "," r5 "," r6 "," r7 "," r8 "," r9 "," r10 "," r11 "," r12 ", " r13 " },
{ " b1 ", " b2 "," b3 "," b4 "," b5 "," b6 "," b7 "," b8 "," b9 "," b10 "," b11 "," b12 ", " b13 " },
{ " g1 ", " g2 "," g3 "," g4 "," g5 "," g6 "," g7 "," g8 "," g9 "," g10 "," g11 "," g12 ", " g13 " },
{ " y1 ", " y2 "," y3 "," y4 "," y5 "," y6 "," y 7"," y8 "," y9 "," y10 "," y11 "," y12 ", " y13 " },
};
//==================================================================
System.out.println("This the first deck:");// after the first round..
display(cards);
System.out.println();
System.out.println("This the first 21 cards :");// after the first 21 cards...
display21(cards);
}// end of main
//========================================================================
public static void display(String x[][]){
for (int i=0; i<x.length; i++) {
for( int j=0; j<x[0].length; j++ ){
System.out.print( x[i][j] );
}
System.out.println();
}
}// end of the method to display the first part of the game.
// ==========================================================
static void displayIdentifyingInformation()
{
System.out.println
(" Write a Java application to implement a card trick using 21 randomly selected cards. "
+ " The interface looks like the following, where the card selected by the user is r9 (which stands for red 9), "
+"and user input is shown in bold: "
+ "Program #4: Mystery 21 "
+ " February 7, 2011 "
+ "Welcome to the 21 card mystery... "
+" Choose a card at random and remember it. "
+ "Then follow the instructions on the screen. ");
}
// end of displayIdentifyingInformation()
}
Explanation / Answer
please rate - thanks
hope you don't mind I changed your display
import java.util.Random;
import java.util.Scanner;
public class Fubar {
public static void main(String[] args)
{
Random rgen = new Random();
displayIdentifyingInformation();
//====================================================================
String[][] cards =
{
{ " r1 ", " r2 "," r3 "," r4 "," r5 "," r6 "," r7 "," r8 "," r9 "," r10 "," r11 "," r12 ", " r13 " },
{ " b1 ", " b2 "," b3 "," b4 "," b5 "," b6 "," b7 "," b8 "," b9 "," b10 "," b11 "," b12 ", " b13 " },
{ " g1 ", " g2 "," g3 "," g4 "," g5 "," g6 "," g7 "," g8 "," g9 "," g10 "," g11 "," g12 ", " g13 " },
{ " y1 ", " y2 "," y3 "," y4 "," y5 "," y6 "," y 7"," y8 "," y9 "," y10 "," y11 "," y12 ", " y13 " },
};
//==================================================================
System.out.println("This the first deck:");// after the first round..
display(cards,52);
System.out.println();
ShuffleCard(cards,rgen);
System.out.println("This the first 21 cards :");// after the first 21 cards...
display (cards,21);
}// end of main
//------------------------------------------------------------------------
private static void ShuffleCard(String x[][],Random rgen){
boolean used[][]=new boolean[4][13];
String temp ;
int randomrow,randomcol;
for(int i=0;i<4;i++)
for(int j=0;j<13;j++)
used[i][j]=false;
for (int i=0; i<4; i++)
for(int j=0;j<13;j++)
{do
{ randomrow = rgen.nextInt(4);
randomcol = rgen.nextInt(13);
}while(used[randomrow][randomcol]);
used[randomrow][randomcol]=true;
temp = x[i][j];
x[i][j] = x[randomrow][randomcol];
x[randomrow][randomcol] = temp;
}
}
//========================================================================
public static void display(String x[][],int num){
for (int i=0; i<x.length; i++) {
for( int j=0; j<x[0].length; j++ ){
System.out.print( x[i][j] );
num--;
if(num==0)
{System.out.println();
return;
}
}
System.out.println();
}
}// end of the method to display the first part of the game.
// ==========================================================
static void displayIdentifyingInformation()
{
System.out.println
(" Write a Java application to implement a card trick using 21 randomly selected cards. "
+ " The interface looks like the following, where the card selected by the user is r9 (which stands for red 9), "
+"and user input is shown in bold: "
+ "Program #4: Mystery 21 "
+ " February 7, 2011 "
+ "Welcome to the 21 card mystery... "
+" Choose a card at random and remember it. "
+ "Then follow the instructions on the screen. ");
}
// end of displayIdentifyingInformation()
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.