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

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 1GZ

Explanation of Solution

Program:

File name: “Card.java

//Defining Card class

class Card

{

    //Declaring variables

    int cardValue;

    String cardSuit;

    String cardRank;  

    //Defining setValue method

    public void setValue(int value)

    {

        cardValue=value;

        //Computing value

        switch(cardValue)

        {

            case 1: cardRank="Ace"; break;

            case 2: cardRank="Two"; break;

            case 3: cardRank="Three"; break;

            case 4: cardRank="Four"; break;

            case 5: cardRank="Five"; break;

            case 6: cardRank="Six"; break;

            case 7: cardRank="Seven"; break;

            case 8: cardRank="Eight"; break;

            case 9: cardRank="Nine"; break;

            case 10: cardRank="Ten"; break;

            case 11: cardRank="Jack"; break;

            case 12: cardRank="Queen"; break;

            case 13: cardRank="King"; break;

            default: cardRank=""; 

        }  

    }

    //Defining setSuit() method

    public void setSuit(String str)

    {

        //Assigning string value to suit

        cardSuit=str;

    }

}

File name: “War2.java

//Import necessary header files

import java.util...

Blurred answer
Students have asked these similar questions
Rectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables).  Remember that a Rectangle has two attributes: Length and Width.  Implement the class by creating a computer program that will ask the user about three rectangle dimensions.  The program should be able to display the total area of the three rectangle objects.  For this exercise, you are required to apply all OOP concepts that you learned in class.   Sample output: Enter Length R1:  1 Enter Width  R1:  1 Enter Length R2:  2 Enter Width  R2:  2 Enter Length R3:  3 Enter Width  R3:  3 The total area of the rectangles is 14.00   Note:  All characters in boldface are user inputs.
You will create a couple of classes that could be used to create a Text Adventure game. The class will be called "Item" and will represent an item in the game that can be carried and used by a player (such as a weapon or a tool). The Item Class The Item class will have only one property: A string description. The Item class will have exactly 3 methods: There will be a default constructor that takes no parameters. This constructor will give a generic, default description of the Item. There will be a constructor that takes a string parameter, and it will initialize the Item's description based on the parameter. There will be a method called "print" that will print the Item's description to standard output. PLEASE MAKE SURE ITS POSSIBLE TO COMPILE WITH THIS CODE. THANKS. #include "Item.h" #include <iostream> #include <string> using namespace std; int main() { Item sword("Sword of Destiny"); Item potion("Healing Potion"); Item key("Key of Wisdom"); string name; cout…
Create a RightTriangle class given the following design: RightTriangle variables: base, height methods: 2 constructors, 1 that set default values and another that accepts to parameters. setBase - changes the base. Requires one parameter for base. setHeight - changes the height. Requires one parameter for height. getBase - returns the triangle base. getHeight - returns the triangle height. area - returns the area of the triangle (1/2bh) given the current base and height
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY