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
This is the question - Create a class named Apartment that holds an apartment number, number of bedrooms, number of baths, and rent amount. Create a constructor that accepts values for each data field. Also create a get method for each field. Write an application that creates at least five Apartment objects. Then prompt a user to enter a minimum number of bedrooms required, a minimum number of baths required, and a maximum rent the user is willing to pay. Display data for all the Apartment objects that meet the user’s criteria or No apartments met your criteria if no such apartments are available. This is the code it has given and I have done some on-  public class Apartment {     int aptNumber;     int bedrooms;     double baths;     double rent;     public Apartment(int num, int bdrms, double bths, double rent) {     }     public int getAptNumber() {         return aptNumber;     }     public int getBedrooms() {         retrun bedrooms;     }     public double getBaths() {…
This is the question - Create a class named Apartment that holds an apartment number, number of bedrooms, number of baths, and rent amount. Create a constructor that accepts values for each data field. Also create a get method for each field. Write an application that creates at least five Apartment objects. Then prompt a user to enter a minimum number of bedrooms required, a minimum number of baths required, and a maximum rent the user is willing to pay. Display data for all the Apartment objects that meet the user’s criteria or No apartments met your criteria if no such apartments are available. This is the code I already have. It doesn't seem to like under TestApartments my apt. variable. I am unsure what to do to fix this cause it doesn't like any of my code -  public class Apartment {     int aptNumber;     int bedrooms;     double baths;     double rent;     public Apartment(int num, int bdrms, double bths, double rent) {         //write code here         aptNumber = num;…
Read the instructions below and write your code using Microsoft Visual Studio (Community version).   Build your own console application with C#. Write a Rectangle class, the private data members are the length (len) and width (wid) of the rectangle, the parameterless constructor sets len and wid to 0, and the parameterized constructor sets the value of length (len) and width (wid). In addition, the class also includes common methods such as calculating the perimeter of the rectangle, calculating the area of the rectangle, obtaining the length value of the rectangle, obtaining the width value of the rectangle, and modifying the length and width values of the rectangle to the corresponding formal parameter values.   Please upload your executable C# file as attachment in the system.
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
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
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