EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
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
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…
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.
Appointment Class Requirements The appointment object shall have a required unique appointment ID string that cannot be longer than 10 characters. The appointment ID shall not be null and shall not be updatable. The appointment object shall have a required appointment Date field. The appointment Date field cannot be in the past. The appointment Date field shall not be null.Note: Use java.util.Date for the appointmentDate field and use before(new Date()) to check if the date is in the past. The appointment object shall have a required description String field that cannot be longer than 50 characters. The description field shall not be null. Appointment Service Requirements The appointment service shall be able to add appointments with a unique appointment ID. The appointment service shall be able to delete appointments per appointment ID.
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