Question

A Driver class that does the following: a. Creates a new deck of cards (unshuffled). b. Displays a menu of choices as follows

This is what I have so far.

I'm getting an error on the ...

case 3: System.out.println("Enter the rank of the card you want removed");

cards.remove();

System.out.println();

break;

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

package PlayingCards;

import java.util.Scanner;

public class Driver

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

boolean done = false;

int menuInput;

DeckOfCards cards = new DeckOfCards();

do

{

System.out.println("Enter the number of one of the choices below:");

System.out.println("1: Shuffle The Deck.");

System.out.println("2: Print The Cards Remaining In The Deck.");

System.out.println("3: Remove All Of The Cards Of A Specific Rank. ");

System.out.println("4: Quit");

menuInput = sc.nextInt();

sc.nextLine();

switch (menuInput)

{

case 1: System.out.println("Shuffled the Deck");

cards.shuffle();

break;

case 2: System.out.println("Printing all cards left in the deck");

cards.print();

break;

case 3: System.out.println("Enter the rank of the card you want removed");

cards.remove();

System.out.println();

break;

case 4: done = true;

System.out.println("Goodbye.");

break;

default: System.out.println("Incorrect entry, please try again.");

}

}

while (!done);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi. I have answered previous part of this question. There was a small error in your code, you didn’t read the rank of cards to remove and was just calling the remove method without rank value. Fixed it. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Driver.java

package PlayingCards;

import java.util.Scanner;

public class Driver

{

    public static void main(String[] args)

    {

         Scanner sc = new Scanner(System.in);

         boolean done = false;

         int menuInput, rank;

         DeckOfCards cards = new DeckOfCards();

         do

         {

             System.out.println("Enter the number of one of the choices below:");

             System.out.println("1: Shuffle The Deck.");

             System.out.println("2: Print The Cards Remaining In The Deck.");

             System.out

                      .println("3: Remove All Of The Cards Of A Specific Rank. ");

             System.out.println("4: Quit");

             menuInput = sc.nextInt();

             sc.nextLine();

             switch (menuInput)

             {

             case 1:

                 System.out.println("Shuffled the Deck");

                 cards.shuffle();

                 break;

             case 2:

                 System.out.println("Printing all cards left in the deck");

                 cards.print();

                 break;

             case 3:

                 System.out

                          .print("Enter the rank of the card you want removed: ");

                 // reading rank value

                 rank = sc.nextInt();

                 // removing all cards with the above rank, assuming rank is

                 // valid. this should be a value between 1 and 13

                 cards.remove(rank);

                 System.out.println();

                 break;

             case 4:

                 done = true;

                 System.out.println("Goodbye.");

                 break;

             default:

                 System.out.println("Incorrect entry, please try again.");

             }

         }

         while (!done);

    }

}

Add a comment
Know the answer?
Add Answer to:
This is what I have so far. I'm getting an error on the ... case 3:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report 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. I also need to create a separate driver class that first outputs the populated deck to prove it...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

  • This is not my entire line of code but the errors I'm getting are from this...

    This is not my entire line of code but the errors I'm getting are from this section. Can you please correct it and tell me where I went wrong? Thank you! package comJava; Vimport java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Scanner; //Lis public Driver { static List<RescueAnimal> list = new ArrayList<>(); public static void main(String[] args) { // Class variables // Create New Dog Dog d = new Dog(); // Create New Monkey Monkey m = new Monkey(); // Method...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • Please make the following code modular. Therefore contained in a package with several classes and not...

    Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q {    public static LinkedList<String> dogs = new LinkedList<String> ();    public static LinkedList<String> cats = new LinkedList<String> ();    public static LinkedList<String> animals = new LinkedList<String> ();    public static void enqueueCats(){        System.out.println("Enter name");        Scanner sc=new Scanner(System.in);        String name = sc.next();        cats.addLast(name);        animals.addLast(name);    }   ...

  • Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...

    Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT