Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
bartleby

Concept explainers

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

Explanation of Solution

Program code:

Card.java

//create a class Card

public class Card

{

//declare class variables

private static char suit;

private static int value;

//define a class method getSuit()

public static char getSuit()

{

//return the value of suit

return suit;

}

//define a class method setSuit()

public static void setSuit(char suit)

{

//set the value of suit

Card.suit = suit;

}

//define a class method getValue()

public static int getValue()

{

//return the value of value

return value;

}

//define a class method setValue()

public static void setValue(int value)

{

//set the value of value

Card.value = value;

}

}

Explanation:

The above snippet of code is used to create a class “Card”. In the code,

  • Import the required header files.
  • Define a class “Card”
    • Declare the class variables “suit” and “value”.
    • Define the “getSuit()” method.
      • Return the value of “suit”
    • Define the “setSuit()” method.
      • Set the value of “suit”
    • Define the “getValue()” method.
      • Return the value of “value”
    • Define the “setValue()” method.
      • Set the value of “value”

PickTwoCards.java

//import the required files

import java.util.Random;

//define a class PickTwoCards

public class PickTwoCards

{

//declare class member variables

final static int CARDS_IN_SUIT = 13;

final static char[] suits = {'s','h','d','c'};

//define the main() method

public static void main(String args[])

{

//create the object of class Card

Card firstCardSelected = selectACard();

//print the statement

System.out.println("Your FIRST Card is Selected with::");

System.out.println("********************************");

//call the method getSuit()

System.out.println("Suit ::"+firstCardSelected.getSuit());

//call the method getValue()

System.out.println("Value ::"+firstCardSelected.getValue()+"\n");

//create the object of class Card

Card secondCardSelected = selectACard();

//print the statement

System.out.println("Your SECOND Card is Selected with::");

System.out.println("********************************");

//call the method getSuit()

System.out.println("Suit ::"+secondCardSelected.getSuit());

//call the method getValue()

System.out.println("Value ::"+secondCardSelected.getValue()+"\n");

}

//define a method selectACard()

public static Card selectACard()

{

//create the object of class Card

Card card = new Card();

//call the method setSuit()

card...

Blurred answer
Students have asked these similar questions
Create a MagicalPotionShop class, this class needs a field called potions.    The potions field should be an ArrayList of the type Potion.    Create a MagicalPotion class, this class needs two fields one called name,    the other called effect. Both of the fields should be Strings.
The Spider Game Introduction: In this assignment you will be implementing a game that simulates a spider hunting for food using python. The game is played on a varying size grid board. The player controls a spider. The spider, being a fast creature, moves in the pattern that emulates a knight from the game of chess. There is also an ant that slowly moves across the board, taking steps of one square in one of the eight directions. The spider's goal is to eat the ant by entering the square it currently occupies, at which point another ant begins moving across the board from a random starting location. Game Definition: The above Figure illustrates the game. The yellow box shows the location of the spider. The green box is the current location of the ant. The blue boxes are the possible moves the spider could make. The red arrow shows the direction that the ant is moving - which, in this case, is the horizontal X-direction. When the ant is eaten, a new ant is randomly placed on one of the…
Please do it in JavaScript or C# 1) Design and implement the class structure for a drawing application. A drawing is made up of a canvas that contains a collection of three different shapes: circles, lines, and boxes. Each shape can be drawn by calling a Draw() method for that shape. The canvas class should also have a draw method that draws all of the shapes it contains. You don’t have to actually draw anything on a screen; you can simulate drawing by writing a message to the console.For example, the code snippet: canvas.Draw();Drawing a circle at...Drawing a line at...etc. (For each shape on the canvas) 2)(Bonus) Consider re-writing the above answer (#1) differently where the canvas does not contain the shapes, but is able to draw any of the three shapes passed to it. Re-design canvas.Draw() if you need to. Your main() program should ask for user input on what shape to draw. Ask once, draw, then exit.could produce something like the following output to the console:
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
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT