Question: Create a class call Card.java , it should contain at least 2 variables one is suit(Spade , Heart, Diamond, Club) and the other one is

Create a class call Card.java, it should contain at least 2 variables one is suit(Spade , Heart, Diamond, Club) and the other one is rank(1~13). Please new 26 card instances using the followings:

// You should know how to use the following code to achieve what you want.

import java.util.*;

Card cards[] = new Card[26];

String suit[] = {Spade , Heart, Diamond, Club};

Random r = new Random[52];

for(int i = 0; i < cards.length; i++){

cards[i] = new Card(r.nextInt(13)+1, suit[r.nextInt(100)%4]);

//You should design the above constructor inside the Card.java

}

After this, please sort the array cards. To compare two cards, first of all you have to compare their ranks. If they have the same rank, you have to then compare their suit (Spade > Heart > Diamond, > Club). If two cards are equal to each other, just put them together. Show the array just sorted

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!