he CODE Must be in JAVA. Please show in simplest form and with comments. Please show the outputs as well (Minimum 2) public class Card{    int faceValue;    int suit;    Card(){       this.faceValue = 9;       this.suit = 1;    }    Card(int f,int s){       this.faceValue = f;       this.suit = s;    }    String getfaceValue(){       if(this.faceValue==1)          return "Ace";       else if(this.faceValue==2)          return "Two";       else if(this.faceValue==3)          return "Three";       else if(this.faceValue==4)          return "Four";       else if(this.faceValue==5)          return "Five";       else if(this.faceValue==6)          return "Six";       else if(this.faceValue==7)          return "Seven";       else if(this.faceValue==8)          return "Eight";       else if(this.faceValue==9)          return "Nine";       else if(this.faceValue==10)          return "Ten";       else if(this.faceValue==11)          return "Jack";       else if(this.faceValue==12)          return "Queen";       else if(this.faceValue==13)          return "King";       else          return "Inavlid";    }    String getSuit(){       if(this.suit==1)          return "Spades";       else if(this.suit==2)          return "Hearts";       else if(this.suit==3)          return "Clubs";       else if(this.suit==4)          return "Diamonds";       else             return "Invalid";    }    void setfaceValue(int s){       this.faceValue = s;    }    void setSuit(int s){       this.suit=s;    }    public String toString(){        return getfaceValue()+" of "+getSuit();     }  } //Test Driver for the Card public class TestDriver{    public static void main(String[] args) {       Card c1 = new Card(1,1);       System.out.println(c1);    } }

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

The CODE Must be in JAVA. Please show in simplest form and with comments. Please show the outputs as well (Minimum 2)

public class Card{
   int faceValue;
   int suit;
   Card(){
      this.faceValue = 9;
      this.suit = 1;
   }
   Card(int f,int s){
      this.faceValue = f;
      this.suit = s;
   }
   String getfaceValue(){
      if(this.faceValue==1)
         return "Ace";
      else if(this.faceValue==2)
         return "Two";
      else if(this.faceValue==3)
         return "Three";
      else if(this.faceValue==4)
         return "Four";
      else if(this.faceValue==5)
         return "Five";
      else if(this.faceValue==6)
         return "Six";
      else if(this.faceValue==7)
         return "Seven";
      else if(this.faceValue==8)
         return "Eight";
      else if(this.faceValue==9)
         return "Nine";
      else if(this.faceValue==10)
         return "Ten";
      else if(this.faceValue==11)
         return "Jack";
      else if(this.faceValue==12)
         return "Queen";
      else if(this.faceValue==13)
         return "King";
      else
         return "Inavlid";
   }
   String getSuit(){
      if(this.suit==1)
         return "Spades";
      else if(this.suit==2)
         return "Hearts";
      else if(this.suit==3)
         return "Clubs";
      else if(this.suit==4)
         return "Diamonds";
      else   
         return "Invalid";
   }
   void setfaceValue(int s){
      this.faceValue = s;
   }
   void setSuit(int s){
      this.suit=s;
   }
   public String toString(){ 
      return getfaceValue()+" of "+getSuit(); 
   } 
}

//Test Driver for the Card


public class TestDriver{
   public static void main(String[] args) {
      Card c1 = new Card(1,1);
      System.out.println(c1);
   }
}

In Assignment 4, you created a Card class that represents a standard playing card. Use this to design and implement a class called
DeckofCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of
cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. Document your
design with a UML Class diagram. Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the
deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck.
Hint: The constructor for DeckOfCards should have nested for loops for the face values (1 to 13) within the suit values (1 to 4) calling the
two parameter constructor. The shuffle method does not have to simulate how a deck is physically shuffled; you can achieve the same
effect by repeatedly swapping pairs of cards chosen at random.
Testing: Include two complete runs to demonstrate the random effect of shuffling.
Transcribed Image Text:In Assignment 4, you created a Card class that represents a standard playing card. Use this to design and implement a class called DeckofCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. Document your design with a UML Class diagram. Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck. Hint: The constructor for DeckOfCards should have nested for loops for the face values (1 to 13) within the suit values (1 to 4) calling the two parameter constructor. The shuffle method does not have to simulate how a deck is physically shuffled; you can achieve the same effect by repeatedly swapping pairs of cards chosen at random. Testing: Include two complete runs to demonstrate the random effect of shuffling.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT