Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Code During each round, players choose a move, which may be either Gdishus, Derflrg, Kullen, Koppang, or Songesand. The rules are: Songesand beats Kullen,

Java Code

During each round, players choose a move, which may be either Gdishus, Derflrg, Kullen, Koppang, or Songesand. The rules are:

  • Songesand beats Kullen, Gdishus
  • Kullen beats Derflrg, Koppang
  • Derflrg beats Songesand, Gdishus
  • Gdishus beats Koppang, Kullen
  • Koppang beats Songesand, Derflrg

Your program should behave as follows:

  • The rules should be printed to the screen
  • The user is asked if they'd like to play a round
    • if they choose 'y', a round is played
    • if they choose 'n', the program ends
  • Until the user has chosen to quit, another round is played.
  • In a round of play:
    • The user is asked to enter a move, which may be either Gdishus, Derflrg, Kullen, Koppang, or Songesand. The program should continue to prompt the user until a valid move is entered.
    • The computer makes a move at random. (Hint: remember how we generated random numbers in class.)
    • The program prints the computer's move, the user's move, and who is the winner of this round.
    • The user is asked if they'd like to continue.
  • When the user has decided to quit the game, the program prints the number of:
    • rounds played
    • times the user won
    • times the computer won
    using switch and here is some suggestion:
    /* use named constants */ public static final int GODISHUS = 0; public static final int DERFLURG = 1; public static final int KULLEN = 2; public static final int KOPPANG = 3; public static final int SONGESAND = 4; /* write a method that is passed two moves and returns who wins */ public static boolean userWon(int userMove, int computerMove) { /* good */ if (userMove == GODISHUS && (computerMove == DERFLURG || computerMove == WHATEVER)) /* not as good */ if (userMove == 1 && computerMove == 2 || computerMove .. } /* returns computer's random move */ public static int randMove() { ... } ... /* using the method */ int computerMove = randMove(); System.out.println("computer entered: " + intMoveToString(computerMove)); /* in response to question about what would happen if we really wanted the String representation of a move */ public static String intMoveToString(int m) { if (m == GODISHUS) { return "Godishus"; } else if (m == DERFLURG) { ... } etc. }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions

Question

List the advantages and disadvantages of the pay programs. page 505

Answered: 1 week ago