Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have 2 classes MyCard.java and MyDeck.java and I need a Test.java class so tha

ID: 440567 • Letter: I

Question

I have 2 classes MyCard.java and MyDeck.java and I need a Test.java class so that way if the program is run , user will have a menu option with : 1-Display the deck 2- shuffle the deck 3- Quit package cards; public class MyCard{ //Each card will have one SUIT and ONE RANK public enum SUIT { SPADE,DIAMOND,HEART,CLUB}; public enum RANK { ACE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING}; public String getSuit(SUIT s){ switch(s){ case SPADE: return "S"; case DIAMOND: return "D"; case HEART: return "H"; case CLUB: return "C"; default : return null; } } public String getRank(RANK r){ switch(r){ case ACE : return "01"; case TWO : return "02"; case THREE : return "03"; case FOUR : return "04"; case FIVE : return "05"; case SIX : return "06"; case SEVEN : return "07"; case EIGHT : return "08"; case NINE : return "09"; case TEN : return "10"; case JACK : return "11"; case QUEEN : return "12"; case KING : return "13"; default : return null; } } SUIT suit; RANK rank; public MyCard(SUIT suit,RANK rank){ this.suit = suit; this.rank = rank; } // get suit of this card public String getSuit(){ return getSuit(this.suit); } // get rank of this card public String getRank(){ return getRank(this.rank); } // compare two suits public boolean compareSuit(SUIT s){ return this.suit == s; } //compare two ranks public boolean compareRank(RANK r){ return this.rank == r; } } ********************************* package cards; import cards.MyCard.RANK; import cards.MyCard.SUIT; public class MyDeck { public MyCard cards[] ; public MyDeck(){ cards = new MyCard[52]; for ( int i = 0 ; i < 4 ;i++ ){ for ( int j = 0 ; j < 13 ; j++){ SUIT s = SUIT.values()[i]; RANK r = RANK.values()[j]; MyCard mc = new MyCard(s,r); cards[j*4+i] = mc; } } } //Generates a random permutation of the array using Knuth's shuffle algorithm public void shuffle(){ for (int i = 0; i < cards.length; i++){ int k = i + (int) (Math.random() * (cards.length - i)); MyCard temp = cards[i]; cards[i] = cards[k]; cards[k] = temp; } } // it has been proven that after 7 shuffle we can get a good random deck of cards ,but 6 shuffles does not make sure that it is good. public void goodShuffle(){ for ( int i = 0 ;i < 7;i++) shuffle(); } public void printDeck(){ for ( int i = 0 ; i < 4 ;i++){ for ( int j = 0 ; j < 13 ; j++){ MyCard c = cards[4*j+i]; System.out.print(c.getSuit() + c.getRank() + " " ); } } System.out.println(); System.out.println(); System.out.println(); } } PLEASE HELP...tHANKS

Explanation / Answer

public class MyCard{ //Each card will have one SUIT and ONE RANK
   public enum SUIT { SPADE,DIAMOND,HEART,CLUB};
   public enum RANK { ACE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING};
   public String getSuit(SUIT s){
    switch(s){
        case SPADE:
                 return "S";
         case DIAMOND:
                return "D";
         case HEART:
                 return "H";
          case CLUB:
                  return "C";
          default :
               return null;
      }
   }
   public String getRank(RANK r){
      switch(r){
            case ACE :
                  return "01";
            case TWO :
                  return "02";
            case THREE :
                  return "03";
              case FOUR :
                    return "04";
              case FIVE :
                          return "05";
               case SIX :
                      return "06";
               case SEVEN :
                     return "07";
               case EIGHT :
                      return "08";
                 case NINE :
                        return "09";
                  case TEN :
                        return "10";
                  case JACK :
                          return "11";
                   case QUEEN :
                          return "12";
                    case KING :
                             return "13";
                      default :
                            return null;
                }
       }
    SUIT suit;
    RANK rank;
public MyCard(SUIT suit,RANK rank){
                   this.suit = suit;
                  this.rank = rank;
     } // get suit of this card
    public String getSuit(){
                  return getSuit(this.suit);
        } // get rank of this card
    public String getRank(){
              return getRank(this.rank);
       } // compare two suits
     public boolean compareSuit(SUIT s){
              return this.suit == s;
       } //compare two ranks
    public boolean compareRank(RANK r){
           return this.rank == r;

      }
}

import cards.MyCard.RANK;
import cards.MyCard.SUIT;
public class MyDeck {
public MyCard cards[] ;
public MyDeck(){
    Mycard cards = new MyCard[52];
    for ( int i = 0 ; i < 4 ;i++ ){
for ( int j = 0 ; j < 13 ; j++){
   SUIT s = SUIT.values()[i];
   RANK r = RANK.values()[j];
   MyCard mc = new MyCard(s,r);
   cards[j*4+i] = mc;
   }
           }
                          //Generates a random permutation of the array using Knuth's shuffle algorithm
         public void shuffle(){
                 for (int i = 0; i < cards.length; i++){
                     int k = i + (int) (Math.random() * (cards.length - i));
                MyCard temp = cards[i];
                cards[i] = cards[k];
                cards[k] = temp;
              }
             } // it has been proven that after 7 shuffle we can get a good random deck of cards ,but 6 shuffles does not make sure that it is good.
           public void goodShuffle(){
                      for ( int i = 0 ;i < 7;i++)
                       shuffle();
             }
   public void printDeck(){
for ( int i = 0 ; i < 4 ;i++){
                for ( int j = 0 ; j < 13 ; j++){
                       MyCard c = cards[4*j+i];
                      System.out.print(c.getSuit() + c.getRank() + " " );
                 }
           }
          System.out.println();
            System.out.println();
          System.out.println();
          }
}