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
Assignment Description This program will simulate part of the game of Yahtzee! This is a dice game that involves rolling five dice and scoring points based on what show up on those five dice. The players would record their scores on a score card, and then total them up, and the player with the larger total wins the game. A Yahtzee score card has two portions: The upper portion has spaces for six scores, obtained by adding up all of the 1's, 2's, 3's, etc. The lower portion has special scores for various combinations: Three of a kind -- at least 3 dice are the same number;the score is the sum of all five dice Four of a kind -- at least 4 dice are the same number;the score is the sum of all five dice Small straight -- four consecutive numbers are represented, e.g. 2345;the score is 25 points Large straight -- five consecutive numbers are represented, e.g. 23456;the score is 30 points Full House -- three of one kind, two of another; the score is 30 points Yahtzee! -- five of a kind; the…
PYTHON:  In this assignment, you will use all of the graphics commands you have learned to create an animated scene. Your program should have a clear theme and tell a story. You may pick any school-appropriate theme that you like. The program must include a minimum of: 5 circles 5 polygons 5 line commands 2 for loops 1 global variable You may wish to use the standard code for simplegui graphics below: import simplegui def draw_handler(canvas): frame = simplegui.create_frame('Testing', 600, 600) frame.set_canvas_background("Black") frame.set_draw_handler(draw_handler) frame.start()
A class object can encapsulate more than one [answer].
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