EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 5, Problem 3GZ
Program Plan Intro

Card game

Program plan:

  • In a file “Card.java”, create a class “Card”,
    • Declare and initialize the necessary variables.
    • Define the method “get_Suit()” to return the suit value.
    • Define the method “get_Value()” to return the value.
    • Define the method “set_Suit()” to set the suit value.
    • Define the method “set_Value()”,
      • Check whether the value is greater than or equal to low and less than or equal to high value,
        • If it is true, set the given integer as the value.
      • Otherwise,
        • Set the lowest value.
  • In a file “War.java”, create a class “War”,
    • Define the method “main ()”,
      • Declare and initialize the necessary variables.
      • Create two objects for “Card” class.
      • Generate the random value for the player.
      • Generate the random value for the computer.
      • Set the value for the player and the computer.
      • Generate the random suit for the player and the computer.
      • Check whether the random value and the suite value of the player is same as that of computer,
        • If it is true, increment the computer’s suit value by “1”.
        • Check whether the computer’s suit value is greater than the highest value,
          • Set the computer’s suit value to “1”.
      • Check whether the player’s suit is “1”,
        • If it is true, call the method “set_Suit()” with “s” as the parameter.
      • Otherwise, check whether the player’s suit is “2”,
        • If it is true, call the method “set_Suit()” with “h” as the parameter.
      • Otherwise, check whether the player’s suit is “3”,
        • If it is true, call the method “set_Suit()” with “d” as the parameter.
      • Otherwise,
        • Call the method “set_Suit()” with “c” as the parameter.
      • Check whether the computer’s suit value is “1”,
        • If it is true, call the method “set_Suit()” with “s” as the parameter.
      • Otherwise, check whether the computer’s suit is “2”,
        • If it is true, call the method “set_Suit()” with “h” as the parameter.
      • Otherwise, check whether the computer’s suit is “3”,
        • If it is true, call the method “set_Suit()” with “d” as the parameter.
      • Otherwise,
        • Call the method “set_Suit()” with “c” as the parameter.
      • Print the messages in the console.
      • Check whether the player’s value is same as the computer’s value,
        • If it is true, print the string “It’s a tie”.
      • Otherwise, check whether the player’s value is greater than the computer’s value,
        • If it is true, print the string “I win”.
      • Otherwise, print the string “You win”.

Blurred answer
Students have asked these similar questions
__eq__(self, other):  Method that returns True if self and other are considered the same Flight: if the origin and destination are the same for both Flights. Make sure that if “other” variable is not a Flight object, this means False should be returned.    getFlightNumber(self):  Getter that returns the Flight number   getStart(self): Getter that returns the Plane Start    getgoingTo(self):  Getter that returns the Plane destination    isDomesticFlight(self):  Method that returns True if the flight is domestic, EX within a country (the Start and goingTo are in the same country); returns False if the flight is international (the Start and goingTo are in different countries)    setStart(self, origin): Setter that sets (updates) the Plane Start    setgoingTo(self, destination): Setter that sets (updates) the Plane GoingTo
Hi I like this code but is it possible to incorportate the 3 methods, because i dont see it in the current code -  void yourTurn ( ) - This method handles moves made by the user. It displays the game board and asks the user to enter a move.  If the move is invalid, it prompts user to enter a valid move again. A valid move refers to one of the empty cells in the board. void machineTurn ( ) - This method handles moves by the computer.  One possibility is to search for an empty position in the array and mark it for the computer player main ( ) - The main method controls the game. You will declare an array for the game and make use of the methods that you have written to produce behavior of the Tic-Tac-Toe game. The human player always makes the first move in the game.  You should alternate between the human player and the computer. After each move you should check for a winner using the checkWinner method. While there is no winner, you should display the gameboard, ask the user for next…
Java Program - GUI Number Guessing Look at the code, notice that the actionPerformed method is not complete. It just contains code that will print to the console when buttons are pressed. Make the following modifications to the code.  When the Higher button is pressed invoke this.guesser.higher(), and then put the new guess into the this.guessField When the Lower button is pressed invoke this.guesser.lower() and then put the new guess into the this.guessField When the Reset button is pressed, invoke this.guesser.reset() and then put the new guess into the ghis.guessField When the Correct button is pressed, exit the app using System.exit(0). Wrap the invocation of lower() and higher() in try catch blocks that catch NumberGuesserIllegalStateExceptions. Show a JOptionPane that alerts the user that you are onto their schemes. Change the guessing algorithm from random-guess to binary search. You can do this by changing the object created for the guesser to a plain old NumberGuesser. It…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY