SlideShare a Scribd company logo
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 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
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;
//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 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
Cards remaining 3
3 of diamonds
Cards remaining 2
3 of hearts
Cards remaining 1
8 of Clubs
Cards remaining 0
_________________________________________________________________________

More Related Content

Similar to This is the final code which meets your requirement.Than youCard.j.pdf

Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdf
charanjit1717
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
AustinIKkNorthy
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
feelinggifts
 

Similar to This is the final code which meets your requirement.Than youCard.j.pdf (9)

Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)
 
Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdf
 
Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)
 
Puzzle with sql set
Puzzle with sql   setPuzzle with sql   set
Puzzle with sql set
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
 
Comp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source codeComp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source code
 

More from aplolomedicalstoremr

Statistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdfStatistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdf
aplolomedicalstoremr
 
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdfSecondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
aplolomedicalstoremr
 
Polygon .java package chegg2;public class Polygon { Var.pdf
Polygon .java package chegg2;public class Polygon {  Var.pdfPolygon .java package chegg2;public class Polygon {  Var.pdf
Polygon .java package chegg2;public class Polygon { Var.pdf
aplolomedicalstoremr
 
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdfOutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
aplolomedicalstoremr
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdf
aplolomedicalstoremr
 
Incapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdfIncapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdf
aplolomedicalstoremr
 
Go with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdfGo with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdf
aplolomedicalstoremr
 
Flexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdfFlexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdf
aplolomedicalstoremr
 
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdfEnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
aplolomedicalstoremr
 
Classification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdfClassification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdf
aplolomedicalstoremr
 
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdfAssets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
aplolomedicalstoremr
 
ANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdfANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdf
aplolomedicalstoremr
 

More from aplolomedicalstoremr (20)

You have to leave solids and liquids out of the equation. This lea.pdf
You have to leave solids and liquids out of the equation. This lea.pdfYou have to leave solids and liquids out of the equation. This lea.pdf
You have to leave solids and liquids out of the equation. This lea.pdf
 
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdf
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdfTungsten is a body centered cubic latticeSolutionTungsten is a.pdf
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdf
 
Statistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdfStatistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdf
 
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdfSecondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
 
Polygon .java package chegg2;public class Polygon { Var.pdf
Polygon .java package chegg2;public class Polygon {  Var.pdfPolygon .java package chegg2;public class Polygon {  Var.pdf
Polygon .java package chegg2;public class Polygon { Var.pdf
 
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdfprobability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
 
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdfOutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
 
Matter is made up of electrically charge particle but the Constituen.pdf
Matter is made up of electrically charge particle but the Constituen.pdfMatter is made up of electrically charge particle but the Constituen.pdf
Matter is made up of electrically charge particle but the Constituen.pdf
 
it is a polynomial of degree 3Solutionit is a polynomial of de.pdf
it is a polynomial of degree 3Solutionit is a polynomial of de.pdfit is a polynomial of degree 3Solutionit is a polynomial of de.pdf
it is a polynomial of degree 3Solutionit is a polynomial of de.pdf
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdf
 
Intitially take a graph sheet and plot the points and the whole figu.pdf
Intitially take a graph sheet and plot the points and the whole figu.pdfIntitially take a graph sheet and plot the points and the whole figu.pdf
Intitially take a graph sheet and plot the points and the whole figu.pdf
 
Incapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdfIncapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdf
 
Go with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdfGo with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdf
 
Flexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdfFlexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdf
 
f(x) = cos(x)Solutionf(x) = cos(x).pdf
f(x) = cos(x)Solutionf(x) = cos(x).pdff(x) = cos(x)Solutionf(x) = cos(x).pdf
f(x) = cos(x)Solutionf(x) = cos(x).pdf
 
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdfEnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
 
Classification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdfClassification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdf
 
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdfAssets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
 
Hypothesis Test for population variance If we have a sample fro.pdf
 Hypothesis Test for population variance If we have a sample fro.pdf Hypothesis Test for population variance If we have a sample fro.pdf
Hypothesis Test for population variance If we have a sample fro.pdf
 
ANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdfANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdf
 

Recently uploaded

Recently uploaded (20)

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 

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 _________________________________________________________________________