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
Write code that creates a Random object and then assigns a random integer in the range of 100 through 399 to the variable randomNumber.
In Chapter 4, you created a Die application that randomly “throws” five dice for the computer and five dice for the player. The application displays the values. Modify the application to decide the winner based on the following hierarchy of Die values. Any higher combination beats a lower one—for example, five of a kind beats four of a kind. Five of a kind Four of a kind Three of a kind A pair For this game, the dice values do not count; for example, if both players have three of a kind, it’s a tie, no matter what the values of the three dice are. Additionally, the game does not recognize other poker hand type combinations such as a full house (three of a kind plus two of a kind) or a straight (sequential values). Figure 8-21 shows a sample execution. Save the application as FiveDice2.java.   Improve the FiveDice2 game so that when both players have the same combination of dice, the higher value wins. For example, two 6s beats two 5s. Save the application as FiveDice3.java.
__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
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