JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
9th Edition
ISBN: 9780357616673
Author: FARRELL
Publisher: CENGAGE L
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
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…
// Question 4: // Declare an integer variable named "variables with an initial value of 10. // Write a method named "SetToOne" that takes one out parameter. // The method should set the out parameter to 1. // Call the method SetToOne passing variables in the btnQ4 click method. // Display the variable variables in the lblQ4. private void btn04_Click(object sender, EventArgs e) {
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