SlideShare a Scribd company logo
1 of 7
Download to read offline
Answer
import java.util.Random;
class DeckMaster
{
public static void main(String[] args)
{
Deck mydeck;
mydeck= new Deck();
mydeck.printDeck();
mydeck.shuffleDeck();
mydeck.printDeck();
Deck mydeck1;
mydeck1= new Deck();
mydeck1.printDeck();
System.out.println("Hello " + mydeck ); //Display the output
while (!mydeck.emptyDeck())
{
int card=mydeck.dealDeck();
System.out.println("Card is " + card);
}
System.out.println("Program Finishing!!!!");
}// of main
} // of DeckMaster
class Deck
{
int [] card_deck;
static int count;
Deck() // constructor--must keep track of total objects created for class
{
count=0;
card_deck = new int[52];
int temp,status=0;
Random randomGenerator= new Random();
for(int i=0;i<52;i++)
{
temp=randomGenerator.nextInt(51)+1;
for(int j=i-1;j>=0;j--)
{
if(temp==card_deck[j])
{
status=1;
break;
}
}
if(status==0)
{
card_deck[i]=temp;
}
else
{
i--;
continue;
}
}
}
//String toString(); // rewrite print of object
void shuffleDeck()// mutator , resets deck to 52 cards, permuted.
{
int temp,status=0;
Random randomGenerator= new Random();
for(int i=0;i<52;i++)
{
temp=randomGenerator.nextInt(51)+1;
for(int j=i-1;j>=0;j--)
{
if(temp==card_deck[j])
{
status=1;
break;
}
}
if(status==0)
{
card_deck[i]=temp;
}
else
{
i--;
continue;
}
}
}
void printDeck() //Accessor --print 10 cards per line with a comma separator.
{
for(int i=0;i<52;i++)
{
System.out.println("deck "+(i+1)+" : "+card_deck[i]);
}
}
int dealDeck() // returns the first element on the card, deck gets smaller
{
int first;
first=card_deck[0];
for(int i=0;i<52;i++)
{
if(i==(51-count))
{
card_deck[51-count]=100;
count++;
break;
}
else
{
card_deck[i]=card_deck[i+1];
}
}
return first;
}
boolean emptyDeck() // True if there is nothing left on the Deck
{
int status=0;
for(int i=0;i<52;i++)
{
if(card_deck[i]!=100)
{
status=1;break;
}
}
if(status==0)
return true;
else
return false;
}
}
Solution
Answer
import java.util.Random;
class DeckMaster
{
public static void main(String[] args)
{
Deck mydeck;
mydeck= new Deck();
mydeck.printDeck();
mydeck.shuffleDeck();
mydeck.printDeck();
Deck mydeck1;
mydeck1= new Deck();
mydeck1.printDeck();
System.out.println("Hello " + mydeck ); //Display the output
while (!mydeck.emptyDeck())
{
int card=mydeck.dealDeck();
System.out.println("Card is " + card);
}
System.out.println("Program Finishing!!!!");
}// of main
} // of DeckMaster
class Deck
{
int [] card_deck;
static int count;
Deck() // constructor--must keep track of total objects created for class
{
count=0;
card_deck = new int[52];
int temp,status=0;
Random randomGenerator= new Random();
for(int i=0;i<52;i++)
{
temp=randomGenerator.nextInt(51)+1;
for(int j=i-1;j>=0;j--)
{
if(temp==card_deck[j])
{
status=1;
break;
}
}
if(status==0)
{
card_deck[i]=temp;
}
else
{
i--;
continue;
}
}
}
//String toString(); // rewrite print of object
void shuffleDeck()// mutator , resets deck to 52 cards, permuted.
{
int temp,status=0;
Random randomGenerator= new Random();
for(int i=0;i<52;i++)
{
temp=randomGenerator.nextInt(51)+1;
for(int j=i-1;j>=0;j--)
{
if(temp==card_deck[j])
{
status=1;
break;
}
}
if(status==0)
{
card_deck[i]=temp;
}
else
{
i--;
continue;
}
}
}
void printDeck() //Accessor --print 10 cards per line with a comma separator.
{
for(int i=0;i<52;i++)
{
System.out.println("deck "+(i+1)+" : "+card_deck[i]);
}
}
int dealDeck() // returns the first element on the card, deck gets smaller
{
int first;
first=card_deck[0];
for(int i=0;i<52;i++)
{
if(i==(51-count))
{
card_deck[51-count]=100;
count++;
break;
}
else
{
card_deck[i]=card_deck[i+1];
}
}
return first;
}
boolean emptyDeck() // True if there is nothing left on the Deck
{
int status=0;
for(int i=0;i<52;i++)
{
if(card_deck[i]!=100)
{
status=1;break;
}
}
if(status==0)
return true;
else
return false;
}
}

More Related Content

Similar to Answerimport java.util.Random; class DeckMaster { public sta.pdf

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
 
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
voversbyobersby
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
anjandavid
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
TLPI - 6 Process
TLPI - 6 ProcessTLPI - 6 Process
TLPI - 6 Process
Shu-Yu Fu
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
Palak Sanghani
 

Similar to Answerimport java.util.Random; class DeckMaster { public sta.pdf (20)

Design Patterns in .Net
Design Patterns in .NetDesign Patterns in .Net
Design Patterns in .Net
 
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
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Libtcc and gwan
Libtcc and gwanLibtcc and gwan
Libtcc and gwan
 
Libtcc and gwan
Libtcc and gwanLibtcc and gwan
Libtcc and gwan
 
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
 
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
TLPI - 6 Process
TLPI - 6 ProcessTLPI - 6 Process
TLPI - 6 Process
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
Debugging & Tuning in Spark
Debugging & Tuning in SparkDebugging & Tuning in Spark
Debugging & Tuning in Spark
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
Encoder + decoder
Encoder + decoderEncoder + decoder
Encoder + decoder
 

More from ankurbhargava44

The common ion effect is responsible for the reduction in the solubi.pdf
The common ion effect is responsible for the reduction in the solubi.pdfThe common ion effect is responsible for the reduction in the solubi.pdf
The common ion effect is responsible for the reduction in the solubi.pdf
ankurbhargava44
 
The DNA matching is carried out by comparing the DNA sequences of th.pdf
The DNA matching is carried out by comparing the DNA sequences of th.pdfThe DNA matching is carried out by comparing the DNA sequences of th.pdf
The DNA matching is carried out by comparing the DNA sequences of th.pdf
ankurbhargava44
 
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdf
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdfStormwater BMPs for urban useStormwater runoff is the water flowi.pdf
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdf
ankurbhargava44
 
Rules generally followed are1. Using existing terminology wheneve.pdf
Rules generally followed are1. Using existing terminology wheneve.pdfRules generally followed are1. Using existing terminology wheneve.pdf
Rules generally followed are1. Using existing terminology wheneve.pdf
ankurbhargava44
 

More from ankurbhargava44 (20)

2n+25Solution2n+25.pdf
2n+25Solution2n+25.pdf2n+25Solution2n+25.pdf
2n+25Solution2n+25.pdf
 
Submitting a word file is not possible here.. ).pdf
                     Submitting a word file is not possible here..  ).pdf                     Submitting a word file is not possible here..  ).pdf
Submitting a word file is not possible here.. ).pdf
 
No reaction because you cant form any kind of i.pdf
                     No reaction because you cant form any kind of i.pdf                     No reaction because you cant form any kind of i.pdf
No reaction because you cant form any kind of i.pdf
 
Mass of hydrogen is 1 so due to 2 hydrogens , it .pdf
                     Mass of hydrogen is 1 so due to 2 hydrogens , it .pdf                     Mass of hydrogen is 1 so due to 2 hydrogens , it .pdf
Mass of hydrogen is 1 so due to 2 hydrogens , it .pdf
 
d. 4 epoxide formation take place .pdf
                     d. 4  epoxide formation take place               .pdf                     d. 4  epoxide formation take place               .pdf
d. 4 epoxide formation take place .pdf
 
c. (1) O3 (2) Zn,H2O .pdf
                     c. (1) O3 (2) Zn,H2O                             .pdf                     c. (1) O3 (2) Zn,H2O                             .pdf
c. (1) O3 (2) Zn,H2O .pdf
 
The technique used in this case is FACS or FaCS may refer to Fluore.pdf
The technique used in this case is FACS or FaCS may refer to Fluore.pdfThe technique used in this case is FACS or FaCS may refer to Fluore.pdf
The technique used in this case is FACS or FaCS may refer to Fluore.pdf
 
benzene toluene nonane CCL4 .pdf
                     benzene  toluene  nonane  CCL4                   .pdf                     benzene  toluene  nonane  CCL4                   .pdf
benzene toluene nonane CCL4 .pdf
 
The common ion effect is responsible for the reduction in the solubi.pdf
The common ion effect is responsible for the reduction in the solubi.pdfThe common ion effect is responsible for the reduction in the solubi.pdf
The common ion effect is responsible for the reduction in the solubi.pdf
 
The DNA matching is carried out by comparing the DNA sequences of th.pdf
The DNA matching is carried out by comparing the DNA sequences of th.pdfThe DNA matching is carried out by comparing the DNA sequences of th.pdf
The DNA matching is carried out by comparing the DNA sequences of th.pdf
 
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdf
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdfStormwater BMPs for urban useStormwater runoff is the water flowi.pdf
Stormwater BMPs for urban useStormwater runoff is the water flowi.pdf
 
SolutionIt is given that time slots are random and independent. S.pdf
SolutionIt is given that time slots are random and independent. S.pdfSolutionIt is given that time slots are random and independent. S.pdf
SolutionIt is given that time slots are random and independent. S.pdf
 
Solution 1United states treasury bonds pays semi annual interest .pdf
Solution 1United states treasury bonds pays semi annual interest .pdfSolution 1United states treasury bonds pays semi annual interest .pdf
Solution 1United states treasury bonds pays semi annual interest .pdf
 
since you have 2 mols of O3 going to 3O2 you divide your delta H by .pdf
since you have 2 mols of O3 going to 3O2 you divide your delta H by .pdfsince you have 2 mols of O3 going to 3O2 you divide your delta H by .pdf
since you have 2 mols of O3 going to 3O2 you divide your delta H by .pdf
 
Rules generally followed are1. Using existing terminology wheneve.pdf
Rules generally followed are1. Using existing terminology wheneve.pdfRules generally followed are1. Using existing terminology wheneve.pdf
Rules generally followed are1. Using existing terminology wheneve.pdf
 
Arranging in ascending orderMedian =(8.1+9.1)2 = 8.6Solution.pdf
Arranging in ascending orderMedian =(8.1+9.1)2 = 8.6Solution.pdfArranging in ascending orderMedian =(8.1+9.1)2 = 8.6Solution.pdf
Arranging in ascending orderMedian =(8.1+9.1)2 = 8.6Solution.pdf
 
Please find my code.import java.util.Arrays;import java.util.Ran.pdf
Please find my code.import java.util.Arrays;import java.util.Ran.pdfPlease find my code.import java.util.Arrays;import java.util.Ran.pdf
Please find my code.import java.util.Arrays;import java.util.Ran.pdf
 
only similarity- Mean, median and mode are all different terms of ce.pdf
only similarity- Mean, median and mode are all different terms of ce.pdfonly similarity- Mean, median and mode are all different terms of ce.pdf
only similarity- Mean, median and mode are all different terms of ce.pdf
 
All of the above .pdf
                     All of the above                                 .pdf                     All of the above                                 .pdf
All of the above .pdf
 
Actually [ NH3 ] 2 causes redness in a solution .pdf
                     Actually [ NH3 ] 2 causes redness in a solution  .pdf                     Actually [ NH3 ] 2 causes redness in a solution  .pdf
Actually [ NH3 ] 2 causes redness in a solution .pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

Answerimport java.util.Random; class DeckMaster { public sta.pdf

  • 1. Answer import java.util.Random; class DeckMaster { public static void main(String[] args) { Deck mydeck; mydeck= new Deck(); mydeck.printDeck(); mydeck.shuffleDeck(); mydeck.printDeck(); Deck mydeck1; mydeck1= new Deck(); mydeck1.printDeck(); System.out.println("Hello " + mydeck ); //Display the output while (!mydeck.emptyDeck()) { int card=mydeck.dealDeck(); System.out.println("Card is " + card); } System.out.println("Program Finishing!!!!"); }// of main } // of DeckMaster class Deck { int [] card_deck; static int count; Deck() // constructor--must keep track of total objects created for class { count=0; card_deck = new int[52]; int temp,status=0; Random randomGenerator= new Random(); for(int i=0;i<52;i++) {
  • 2. temp=randomGenerator.nextInt(51)+1; for(int j=i-1;j>=0;j--) { if(temp==card_deck[j]) { status=1; break; } } if(status==0) { card_deck[i]=temp; } else { i--; continue; } } } //String toString(); // rewrite print of object void shuffleDeck()// mutator , resets deck to 52 cards, permuted. { int temp,status=0; Random randomGenerator= new Random(); for(int i=0;i<52;i++) { temp=randomGenerator.nextInt(51)+1; for(int j=i-1;j>=0;j--) { if(temp==card_deck[j]) { status=1; break; } }
  • 3. if(status==0) { card_deck[i]=temp; } else { i--; continue; } } } void printDeck() //Accessor --print 10 cards per line with a comma separator. { for(int i=0;i<52;i++) { System.out.println("deck "+(i+1)+" : "+card_deck[i]); } } int dealDeck() // returns the first element on the card, deck gets smaller { int first; first=card_deck[0]; for(int i=0;i<52;i++) { if(i==(51-count)) { card_deck[51-count]=100; count++; break; } else { card_deck[i]=card_deck[i+1]; } } return first;
  • 4. } boolean emptyDeck() // True if there is nothing left on the Deck { int status=0; for(int i=0;i<52;i++) { if(card_deck[i]!=100) { status=1;break; } } if(status==0) return true; else return false; } } Solution Answer import java.util.Random; class DeckMaster { public static void main(String[] args) { Deck mydeck; mydeck= new Deck(); mydeck.printDeck(); mydeck.shuffleDeck(); mydeck.printDeck(); Deck mydeck1; mydeck1= new Deck(); mydeck1.printDeck(); System.out.println("Hello " + mydeck ); //Display the output while (!mydeck.emptyDeck())
  • 5. { int card=mydeck.dealDeck(); System.out.println("Card is " + card); } System.out.println("Program Finishing!!!!"); }// of main } // of DeckMaster class Deck { int [] card_deck; static int count; Deck() // constructor--must keep track of total objects created for class { count=0; card_deck = new int[52]; int temp,status=0; Random randomGenerator= new Random(); for(int i=0;i<52;i++) { temp=randomGenerator.nextInt(51)+1; for(int j=i-1;j>=0;j--) { if(temp==card_deck[j]) { status=1; break; } } if(status==0) { card_deck[i]=temp; } else { i--; continue;
  • 6. } } } //String toString(); // rewrite print of object void shuffleDeck()// mutator , resets deck to 52 cards, permuted. { int temp,status=0; Random randomGenerator= new Random(); for(int i=0;i<52;i++) { temp=randomGenerator.nextInt(51)+1; for(int j=i-1;j>=0;j--) { if(temp==card_deck[j]) { status=1; break; } } if(status==0) { card_deck[i]=temp; } else { i--; continue; } } } void printDeck() //Accessor --print 10 cards per line with a comma separator. { for(int i=0;i<52;i++) { System.out.println("deck "+(i+1)+" : "+card_deck[i]); }
  • 7. } int dealDeck() // returns the first element on the card, deck gets smaller { int first; first=card_deck[0]; for(int i=0;i<52;i++) { if(i==(51-count)) { card_deck[51-count]=100; count++; break; } else { card_deck[i]=card_deck[i+1]; } } return first; } boolean emptyDeck() // True if there is nothing left on the Deck { int status=0; for(int i=0;i<52;i++) { if(card_deck[i]!=100) { status=1;break; } } if(status==0) return true; else return false; } }