This is the final code which meets your requirement.Than you
Card.java
import java.util.Random;
public class Card {
//declaring instance variables
private String suit;
private int face_value;
public static int count=52;
//Creating an instance of Random class reference
Random rand;
//Default Constructor
public Card() {
super();
//Passing random class object to the Random class reference
rand = new Random();
}
//Getters and setters
public String getSuit() {
return suit;
}
public void setSuit(String suit) {
this.suit = suit;
}
public int getFace_value() {
return face_value;
}
public void setFace_value(int face_value) {
this.face_value = face_value;
}
public int getCount() {
return count;
}
//This shuffle() method will shuffle the deck
public void shuffle()
{
//Picking a card from the deck randomly and find its face value and suit
this.face_value = 1 + rand.nextInt((9) + 1);
int suit_random_value = 1 + rand.nextInt((3) + 1);
if(suit_random_value==1)
{
this.suit=\"Clubs\";
}
else if(suit_random_value==2)
{
this.suit=\"hearts\";
}
else if(suit_random_value==3)
{
this.suit=\"Spades\";
}
else if(suit_random_value==4)
{
this.suit=\"diamonds\";
}
this.count=count-1;
}
}
________________________________________________________________________
DriverClass.java
public class DriverClass {
public static void main(String[] args) {
//creating an array which can hold 52 Card class Objects
Card c[]=new Card[52];
//Creating 52 card class objects and storing them into an array
for(int i=0;i<52;i++)
{
//Creating Card class Object
c[i]=new Card();
}
//Displaying each card face value and its suit.
for(int i=0;i<52;i++)
{
//Shuffling the deck before every card picking from the deck
c[i].shuffle();
//Displaying randomly picked card face value and its suit
System.out.println(c[i].getFace_value()+\" of \"+c[i].getSuit()+\" Cards remaining
\"+c[i].getCount());
}
}
}
_________________________________________________________________________
Output:
8 of diamonds
Cards remaining 51
4 of Clubs
Cards remaining 50
9 of Clubs
Cards remaining 49
7 of Spades
Cards remaining 48
9 of diamonds
Cards remaining 47
7 of diamonds
Cards remaining 46
4 of diamonds
Cards remaining 45
9 of Clubs
Cards remaining 44
5 of hearts
Cards remaining 43
7 of Spades
Cards remaining 42
10 of Clubs
Cards remaining 41
7 of diamonds
Cards remaining 40
8 of diamonds
Cards remaining 39
6 of hearts
Cards remaining 38
4 of hearts
Cards remaining 37
6 of Spades
Cards remaining 36
4 of Clubs
Cards remaining 35
3 of diamonds
Cards remaining 34
9 of diamonds
Cards remaining 33
3 of diamonds
Cards remaining 32
5 of Spades
Cards remaining 31
4 of Clubs
Cards remaining 30
3 of Spades
Cards remaining 29
6 of diamonds
Cards remaining 28
3 of hearts
Cards remaining 27
9 of hearts
Cards remaining 26
7 of hearts
Cards remaining 25
3 of hearts
Cards remaining 24
10 of Clubs
Cards remaining 23
2 of hearts
Cards remaining 22
9 of Clubs
Cards remaining 21
8 of diamonds
Cards remaining 20
8 of Clubs
Cards remaining 19
2 of h.
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
This is the final code which meets your requirement.Than youCard.j.pdf
1. This is the final code which meets your requirement.Than you
Card.java
import java.util.Random;
public class Card {
//declaring instance variables
private String suit;
private int face_value;
public static int count=52;
//Creating an instance of Random class reference
Random rand;
//Default Constructor
public Card() {
super();
//Passing random class object to the Random class reference
rand = new Random();
}
//Getters and setters
public String getSuit() {
return suit;
}
public void setSuit(String suit) {
this.suit = suit;
}
public int getFace_value() {
return face_value;
}
public void setFace_value(int face_value) {
this.face_value = face_value;
}
public int getCount() {
2. return count;
}
//This shuffle() method will shuffle the deck
public void shuffle()
{
//Picking a card from the deck randomly and find its face value and suit
this.face_value = 1 + rand.nextInt((9) + 1);
int suit_random_value = 1 + rand.nextInt((3) + 1);
if(suit_random_value==1)
{
this.suit="Clubs";
}
else if(suit_random_value==2)
{
this.suit="hearts";
}
else if(suit_random_value==3)
{
this.suit="Spades";
}
else if(suit_random_value==4)
{
this.suit="diamonds";
}
this.count=count-1;
}
}
________________________________________________________________________
DriverClass.java
public class DriverClass {
public static void main(String[] args) {
3. //creating an array which can hold 52 Card class Objects
Card c[]=new Card[52];
//Creating 52 card class objects and storing them into an array
for(int i=0;i<52;i++)
{
//Creating Card class Object
c[i]=new Card();
}
//Displaying each card face value and its suit.
for(int i=0;i<52;i++)
{
//Shuffling the deck before every card picking from the deck
c[i].shuffle();
//Displaying randomly picked card face value and its suit
System.out.println(c[i].getFace_value()+" of "+c[i].getSuit()+" Cards remaining
"+c[i].getCount());
}
}
}
_________________________________________________________________________
Output:
8 of diamonds
Cards remaining 51
4 of Clubs
Cards remaining 50
9 of Clubs
Cards remaining 49
7 of Spades
Cards remaining 48
9 of diamonds
Cards remaining 47
7 of diamonds
Cards remaining 46
4. 4 of diamonds
Cards remaining 45
9 of Clubs
Cards remaining 44
5 of hearts
Cards remaining 43
7 of Spades
Cards remaining 42
10 of Clubs
Cards remaining 41
7 of diamonds
Cards remaining 40
8 of diamonds
Cards remaining 39
6 of hearts
Cards remaining 38
4 of hearts
Cards remaining 37
6 of Spades
Cards remaining 36
4 of Clubs
Cards remaining 35
3 of diamonds
Cards remaining 34
9 of diamonds
Cards remaining 33
3 of diamonds
Cards remaining 32
5 of Spades
Cards remaining 31
4 of Clubs
Cards remaining 30
3 of Spades
Cards remaining 29
6 of diamonds
Cards remaining 28
5. 3 of hearts
Cards remaining 27
9 of hearts
Cards remaining 26
7 of hearts
Cards remaining 25
3 of hearts
Cards remaining 24
10 of Clubs
Cards remaining 23
2 of hearts
Cards remaining 22
9 of Clubs
Cards remaining 21
8 of diamonds
Cards remaining 20
8 of Clubs
Cards remaining 19
2 of hearts
Cards remaining 18
9 of Clubs
Cards remaining 17
8 of diamonds
Cards remaining 16
5 of Spades
Cards remaining 15
4 of Spades
Cards remaining 14
5 of Clubs
Cards remaining 13
3 of Clubs
Cards remaining 12
8 of diamonds
Cards remaining 11
9 of Clubs
Cards remaining 10
6. 4 of Clubs
Cards remaining 9
10 of Clubs
Cards remaining 8
1 of hearts
Cards remaining 7
5 of Spades
Cards remaining 6
1 of hearts
Cards remaining 5
4 of Clubs
Cards remaining 4
10 of Clubs
Cards remaining 3
3 of diamonds
Cards remaining 2
3 of hearts
Cards remaining 1
8 of Clubs
Cards remaining 0
_________________________________________________________________________
Solution
This is the final code which meets your requirement.Than you
Card.java
import java.util.Random;
public class Card {
//declaring instance variables
private String suit;
private int face_value;
public static int count=52;
//Creating an instance of Random class reference
Random rand;
7. //Default Constructor
public Card() {
super();
//Passing random class object to the Random class reference
rand = new Random();
}
//Getters and setters
public String getSuit() {
return suit;
}
public void setSuit(String suit) {
this.suit = suit;
}
public int getFace_value() {
return face_value;
}
public void setFace_value(int face_value) {
this.face_value = face_value;
}
public int getCount() {
return count;
}
//This shuffle() method will shuffle the deck
public void shuffle()
{
//Picking a card from the deck randomly and find its face value and suit
this.face_value = 1 + rand.nextInt((9) + 1);
int suit_random_value = 1 + rand.nextInt((3) + 1);
if(suit_random_value==1)
{
this.suit="Clubs";
}
8. else if(suit_random_value==2)
{
this.suit="hearts";
}
else if(suit_random_value==3)
{
this.suit="Spades";
}
else if(suit_random_value==4)
{
this.suit="diamonds";
}
this.count=count-1;
}
}
________________________________________________________________________
DriverClass.java
public class DriverClass {
public static void main(String[] args) {
//creating an array which can hold 52 Card class Objects
Card c[]=new Card[52];
//Creating 52 card class objects and storing them into an array
for(int i=0;i<52;i++)
{
//Creating Card class Object
c[i]=new Card();
}
//Displaying each card face value and its suit.
for(int i=0;i<52;i++)
{
9. //Shuffling the deck before every card picking from the deck
c[i].shuffle();
//Displaying randomly picked card face value and its suit
System.out.println(c[i].getFace_value()+" of "+c[i].getSuit()+" Cards remaining
"+c[i].getCount());
}
}
}
_________________________________________________________________________
Output:
8 of diamonds
Cards remaining 51
4 of Clubs
Cards remaining 50
9 of Clubs
Cards remaining 49
7 of Spades
Cards remaining 48
9 of diamonds
Cards remaining 47
7 of diamonds
Cards remaining 46
4 of diamonds
Cards remaining 45
9 of Clubs
Cards remaining 44
5 of hearts
Cards remaining 43
7 of Spades
Cards remaining 42
10 of Clubs
Cards remaining 41
7 of diamonds
Cards remaining 40
8 of diamonds
10. Cards remaining 39
6 of hearts
Cards remaining 38
4 of hearts
Cards remaining 37
6 of Spades
Cards remaining 36
4 of Clubs
Cards remaining 35
3 of diamonds
Cards remaining 34
9 of diamonds
Cards remaining 33
3 of diamonds
Cards remaining 32
5 of Spades
Cards remaining 31
4 of Clubs
Cards remaining 30
3 of Spades
Cards remaining 29
6 of diamonds
Cards remaining 28
3 of hearts
Cards remaining 27
9 of hearts
Cards remaining 26
7 of hearts
Cards remaining 25
3 of hearts
Cards remaining 24
10 of Clubs
Cards remaining 23
2 of hearts
Cards remaining 22
9 of Clubs
11. Cards remaining 21
8 of diamonds
Cards remaining 20
8 of Clubs
Cards remaining 19
2 of hearts
Cards remaining 18
9 of Clubs
Cards remaining 17
8 of diamonds
Cards remaining 16
5 of Spades
Cards remaining 15
4 of Spades
Cards remaining 14
5 of Clubs
Cards remaining 13
3 of Clubs
Cards remaining 12
8 of diamonds
Cards remaining 11
9 of Clubs
Cards remaining 10
4 of Clubs
Cards remaining 9
10 of Clubs
Cards remaining 8
1 of hearts
Cards remaining 7
5 of Spades
Cards remaining 6
1 of hearts
Cards remaining 5
4 of Clubs
Cards remaining 4
10 of Clubs
12. Cards remaining 3
3 of diamonds
Cards remaining 2
3 of hearts
Cards remaining 1
8 of Clubs
Cards remaining 0
_________________________________________________________________________