孩子的 computer 作业 (翻扑克牌)- 谢谢!

 

 

Result: Whenever I try to remove a triplet of J, Q, and K, my program does not remove them and replace them with new cards. The boolean methods that determine whether or not cards should be removed (either J, Q, and K together or sum pair of 11 are removed and replaced) are below. However, the method that determines whether or not a pair of cards add up to 11 works. Thanks so much!

 

/**

    * Determines if the selected cards form a valid group for removal.

    * In Elevens, the legal groups are (1) a pair of non-face cards

    * whose values add to 11, and (2) a group of three cards consisting of

    * a jack, a queen, and a king in some order.

    * @param selectedCards the list of the indices of the selected cards.

    * @return true if the selected cards form a valid group for removal;

    *     false otherwise.

    */

   public boolean isLegal(List<Integer> selectedCards)

   {

       boolean toReturn = true;

       int jack = 0;

       int queen = 0;

       int king = 0;

       

       for(int count = 0; count < selectedCards.size() - 1; count++)

       {

           for(int counter = count + 1; counter < selectedCards.size(); counter++)

           {

               if(cards[selectedCards.get(count)].pointValue() == 0 || cards[selectedCards.get(counter)].pointValue() == 0)

               {

                   if(cards[selectedCards.get(count)].rank().equals("jack") || cards[selectedCards.get(counter)].rank().equals("jack"))

                   {

                       jack = 11;

                   }

                   else if(cards[selectedCards.get(count)].rank().equals("queen") || cards[selectedCards.get(counter)].rank().equals("queen"))

                   {

                       queen = 12;

                   }

                   else if(cards[selectedCards.get(count)].rank().equals("king") || cards[selectedCards.get(counter)].rank().equals("king"))

                   {

                       king = 13;

                   }

               }

               if(cards[selectedCards.get(count)].pointValue() + cards[selectedCards.get(counter)].pointValue() == 11)

               {     

                   toReturn = true;

                   return true;

               }

               else if(jack == 11 && queen == 12 && king == 13)

               {

                   toReturn = true;

                   return true;

               }

               else

               {

                   toReturn = false;

               }

           }

       }

       return toReturn;

   }

 

--------------

 

   /**

    * Check for a JQK in the selected cards.

    * @param selectedCards selects a subset of this board.  It is list

    *                  of indexes into this board that are searched

    *                  to find a JQK group.

    * @return true if the board entries in selectedCards

    *          include a jack, a queen, and a king; false otherwise.

    */

   private boolean containsJQK(List<Integer> selectedCards)

   {

       boolean toReturn = true;

       int jack = 0;

       int queen = 0;

       int king = 0;

       

       for(int count = 0; count < selectedCards.size(); count++)

       {

           if(cards[selectedCards.get(count)].pointValue() == 0)

           {

               if(cards[selectedCards.get(count)].rank().equals("jack"))

               {

                   jack = 11;

               }

               else if(cards[selectedCards.get(count)].rank().equals("queen"))

               {

                   queen = 12;

               }

               else if(cards[selectedCards.get(count)].rank().equals("king"))

               {

                   king = 13;

               }

           }

       }

           

       if(jack == 11 && queen == 12 && king == 13)

       {

           toReturn = true;

       }

       else

       {

           toReturn = false;

       }

       return toReturn;

   }

 

所有跟帖: 

请问这位家长,发贴是求助,还是夸赞? -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (0 bytes) () 05/24/2018 postreply 13:14:49

求助求助,得不出来想要的结果,最后一个大作业的一部分,谢谢 -cm930118- 给 cm930118 发送悄悄话 (0 bytes) () 05/24/2018 postreply 13:20:03

how card[] was defined? Please post its class here. -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (0 bytes) () 05/24/2018 postreply 13:20:45

When he referred to "the boolean method" and "the method" , plea -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (266 bytes) () 05/24/2018 postreply 13:24:20

Hi, both of these methods involve removing and replacing the J, -cm930118- 给 cm930118 发送悄悄话 (38216 bytes) () 05/24/2018 postreply 13:30:39

please post where card[] was instantiated. -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (299 bytes) () 05/24/2018 postreply 13:41:37

1) I am not sure which method is causing the error, but I know i -cm930118- 给 cm930118 发送悄悄话 (0 bytes) () 05/24/2018 postreply 13:45:52

that the error occurs in one (or both) classes. #2. I tried yo -cm930118- 给 cm930118 发送悄悄话 (0 bytes) () 05/24/2018 postreply 14:02:45

"the error", would you clarify what is "the error" explicitly. -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (1342 bytes) () 05/24/2018 postreply 14:12:06

Here -cm930118- 给 cm930118 发送悄悄话 (304489 bytes) () 05/24/2018 postreply 14:33:20

your test is too faraway from the method you suspect. -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (1267 bytes) () 05/24/2018 postreply 15:16:45

Deck class as follows below: 谢谢! -cm930118- 给 cm930118 发送悄悄话 (0 bytes) () 05/24/2018 postreply 15:24:18

Deck looks good; -LiveInCanada2- 给 LiveInCanada2 发送悄悄话 (1621 bytes) () 05/24/2018 postreply 15:57:53

I did some searching on Google and found out what implementation -cm930118- 给 cm930118 发送悄悄话 (234 bytes) () 05/24/2018 postreply 16:53:00

请您先登陆,再发跟帖!