QuestionQuestion

Go Fish
Every kid plays Go Fish. But just in case you missed this one, two players, say Bette and Bob are each dealt seven cards from a standard deck. Each player in turn may ask the other player if he or she has any cards of a particular rank, for example, “got any kings?” A player cannot request a certain type of card unless he or she holds at least one of that type. For example, Bette cannot ask for kings unless she holds at least one king. If Bob has any kings then he must relinquish all of them to Bette. Bette continues requesting cards from Bob as long as Bob can fulf ll her requests. When Bob can no longer hand over cards to Bette, he tells her to “go fish” and Bette is dealt one more card from the deck. If it happens to be the card she had just unsuccessfully requested, she continues querying Bob for cards; otherwise Bob gets to query Bette. When either player collects all four cards of a particular denomination, he or she immediately removes them from his or her hand and places the “set” off to the side. The game is over when all the cards are made into sets. The player with the most sets wins. Write an application that implements Go Fish so that a human can play against the computer. After each game a player may quit or play again. When a player quits, the program should print summary win/loss statistics.
a. Write a detailed problem description and identify the nouns and verbs of the problem.
b. Determine the classes that your program will use.
c. Determine the methods for each class.
d. Determine the attributes of each class by observing which classes need to send messages to which.
e. Refine your design. Write headers for all methods, but do not yet implement the methods.
f. Complete the implementation using a text-based user interface.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class GoFish {

// Main method which runs game execution
public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int[] score = new int[2];
    String input;
    System.out.println("Welcome to Go Fish!");
    while (true) {
      Deck deck = new Deck();
      Hand computer = new Hand();
      Hand player = new Hand();
      for (int i = 0; i < 7; i++) {
       computer.add(deck.deal());
       player.add(deck.deal());
      }
      // Single game loop
      while (true) {
       // Player move loop
       while (true) {
          ArrayList<String> ranks = player.getRanks();
          if (ranks.size() == 0) {
            System.out.println("Player cannot request any cards and forfeits turn.");
            break;
          }
          System.out.println("Player " + player);
          System.out.println("Player, request a rank:");
          int i = 0;
          for (String rank: ranks) {
            i++;
            System.out.println(" " + i + ": " + rank);
          }
          System.out.print("Player Choice: ");
          input = s.nextLine();
          try {
            i = Integer.parseInt(input);
            if (i >= 1 && i <= ranks.size()) {...
$75.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats