EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
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…
This is the question I am stuck on - Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. This is what I have so far - public class Recording {     private String song;     private String artist;     private int playTime;     public void setSong(String title) {         this.song = title;     }     public void setArtist(String name) {         this.artist = name;     }     public void setPlayTime(int time) {         this.playTime = time;     }     public String getSong() {         return song;     }     public String…
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