Java Programming, Loose-leaf Version
Java Programming, Loose-leaf Version
8th Edition
ISBN: 9781337685917
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
Submission Instructions Follow the instructions for How to Submit Programming Assignments. Assignment First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "Parser" (without the quotation marks) that uses methods to: Get a comma-delimited String of integers (e.g. "4, 8, 16, 32") from the user at the command line and then convert the String to an ArrayList of integers (using the wrapper class) with each element containing one of the input integers in sequence Print the integers to the command line, using a for loop, so that each integer is on a separate line BE SURE TO INCLUDE THE REQUIRED COMMENTS AND DOCUMENTATION AS WELL AS THE OUTPUT FROM MULTIPLE PROGRAM RUNS AS A COMMENT BLOCK AT THE BOTTOM OF YOUR SOURCE CODE FILE.  See Grading Rubric.
Please provide JAVA source code for following assignment with proper comments. Please use basic While/for/ case/ loop for source code, I just started learning and doesn't know a lot about computer programming. 1. Employee Class Write a class named Employee that has the following fields: name. The name field references a String object that holds the employee’s name. idNumber. The idNumber is an int variable that holds the employee’s ID number. department. The department field references a String object that holds the name of the department where the employee works. position. The position field references a String object that holds the employee’s job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employee’s name, employee’s ID number, department, and position. A constructor that accepts the following values as arguments and assigns them to the appropriate…
Suppose you are using a jQuery animation to make an element change color when the user clicks on it, and you also want to execute a function as soon as the animation finishes running. How can you do this? a. Pass the function in as the first argument to theanimate()method called on the element. b. Use anif elseblock with thehasClass()method to determine when to call the function. c. Pass the function in as the final argument to theanimate()method called on the element. d. You cannot accomplish this using jQuery commands.
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