Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you write this following code using processing? String[] suit = { \"Clubs

ID: 3634096 • Letter: H

Question

How do you write this following code using processing?
String[] suit = { "Clubs", "Diamonds", "Hearts", "Spades" };
String[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"
}

int i = (int) (Math.random() * rank.length);
int j = (int) (Math.random() * suit.length);
System.out.println(rank[i] + " of " + suit[j]);
String[] deck = new String[ranks.length * suits.length];
for (int i = 0; i < ranks.length; i++)
for (int j = 0; j < suits.length; j++)
deck[suits.length*i + j] = rank[i] + " of " + suit[j];
System.out.println(rank[i] + " of " + suit[j]);
String t = deck[i];
deck[i] = deck[j];
deck[j] = t;
int N = deck.length;
for (int i = 0; i < N; i++)
{
int r = i + (int) (Math.random() * (N-i));
String t = deck[r];
deck[r] = deck[i];
deck[i] = t;
}
http://processing.org/
http://www.learningprocessing.com/

Explanation / Answer

package javapoker; 02 03 public class Card 04 { 05 private short rank, suit; 06 07 private static String[] suits = { "hearts", "spades", "diamonds", "clubs" }; 08 private static String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" }; 09 10 public static String rankAsString( int __rank ) { 11 return ranks[__rank]; 12 } 13 14 Card(short suit, short rank) 15 { 16 this.rank=rank; 17 this.suit=suit; 18 } 19 20 public @Override String toString() 21 { 22 return ranks[rank] + " of " + suits[suit]; 23 } 24 25 public short getRank() { 26 return rank; 27 } 28 29 public short getSuit() { 30 return suit; 31 } 32 } or package javapoker; 02 03 import java.util.Random; 04 import java.util.ArrayList; 05 06 public class Deck { 07 private ArrayList cards; 08 09 Deck() 10 { 11 cards = new ArrayList(); 12 int index_1, index_2; 13 Random generator = new Random(); 14 Card temp; 15 16 for (int a=1; a
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote