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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started