Concept explainers
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...
Trending nowThis is a popular solution!
Chapter 3 Solutions
Java Programming
- Node A is connected to node B by a 2000km fiber link having a bandwidth of 100Mbps. What is the total latency time (transmit + propagation) required to transmit a 4000 byte file using packets that include 1000 Bytes of data plus 40 Bytes of header.arrow_forwardanswer should avoid using AI and should be basic and explain pleasearrow_forwardasnwer should avoid using AIarrow_forward
- answer should avoid using AI (such as ChatGPT), do not any answer directly copied from AI would and explain codearrow_forwardWrite a c++ program that will count from 1 to 10 by 1. The default output should be: 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10 There should be only a newline after the last number. Each number except the last should be followed by a comma and a space. To make your program more functional, you should parse command line arguments and change behavior based on their values. Argument Parameter Action -f, --first yes, an integer Change place you start counting -l, --last yes, an integer Change place you end counting -s, --skip optional, an integer, 1 if not specified Change the amount you add to the counter each iteration -h, —help none Print a help message including these instructions. -j, --joke none Tell a number based joke. So, if your program is called counter, counter -f 10 --last 4 --skip 2 should produce 10, 8, 6, 4 Please use the last supplied argument. If your code is called counter, counter -f 4 -f 5 -f 6 should count from 6. You should…arrow_forwardshow workarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning