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 (MindTap Course List)
- The __str__ method of the Bank class (in bank.py) returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string in ascending order of name. Implement the __str__ method of the bank class so that it sorts the account values before printing them to the console. In order to sort the account values you will need to define the __eq__ and __lt__ methods in the SavingsAccount class (in savingsaccount.py). The __eq__ method should return True if the account names are equal during a comparison, False otherwise. The __lt__ method should return True if the name of one account is less than the name of another, False otherwise.arrow_forwardThe __str__ method of the Bank class (in bank.py) returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string in ascending order of name. Implement the __str__ method of the bank class so that it sorts the account values before printing them to the console. In order to sort the account values you will need to define the __eq__ and __lt__ methods in the SavingsAccount class (in savingsaccount.py). The __eq__ method should return True if the account names are equal during a comparison, False otherwise. The __lt__ method should return True if the name of one account is less than the name of another, False otherwise. The program should output in the following format: Test for createBank: Name: Jack PIN: 1001 Balance: 653.0 Name: Mark PIN: 1000 Balance: 377.0 ... ... ... Name: Name7 PIN: 1006 Balance: 100.0 bank.py """ File: bank.py Project 9.3 The str for Bank returns a string of accounts sorted by name.…arrow_forwardCreate the StockTask1 Java project Create a Stock object class that contains the following information: The symbol of the stock is stored in a private string data field called symbol. The stock's name is stored in a private string data field called name. previousClosingPrice is a private double data area that stores the stock price for the previous day. currentPrice is a private double data area that stores the stock price at the current time. A constructor for creating a stock with the given symbol and name. For the data fields, there are accessor methods (get-methods). For the data fields, there is a mutator method (set-methods). A method named getChangePercent()that returns the percentage changed from previousClosingPrice to currentPrice. Formula:perc_change = (current price - previous closing price) / previous closing price x 100 Create a test class named testStockthat creates a Stockobject with the stock symbol SUNW, the name Sun Microsystems Inc., and the previous closing…arrow_forward
- A class object can encapsulate more than one [answer].arrow_forward#include "TerminalPlayer.h" Card TerminalPlayer::playCard(const Card& opponentCard) { // if the opponentCard is a Joker we are going first // if the opponentCard is not a Joker we are going second and opponentCard is what our opponent played // Display the player's hand // prompt them to choose a card // remove that card from the hand and return that cardarrow_forwardJAVA LANGUAGE Create an ArrayList, Name it YourRegNoandName that can hold Integers, and fill each slot with a different random value from 1-50. Display those values on the screen, and then prompt the user for an integer to search through the ArrayList, and if the item is present, say “FOUND”. It is not necessary to display anything if the value was not found. If the item is in the ArrayList multiple times, it's okay if the program prints the message more than once. ALSO SCREENSHOT THE OUTPUTarrow_forward
- Rectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables). Remember that a Rectangle has two attributes: Length and Width. Implement the class by creating a computer program that will ask the user about three rectangle dimensions. The program should be able to display the total area of the three rectangle objects. For this exercise, you are required to apply all OOP concepts that you learned in class. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Enter Length R3: 3 Enter Width R3: 3 The total area of the rectangles is 14.00 Note: All characters in boldface are user inputs.arrow_forwardPlease complete the code, in C++ to pass the tests, the first image is the assignment, the second screenshot provides the starter code. The Test case will be: Sample Test Case: Enter the size of the board: 7 Enter the number of tests: 500 Enter the random seed: 17 500 248 252 135 239 126 72 188 182 58 36 132 177 124 31 19 71 180 139 71 20 7 45 130 155 105 46 12arrow_forward1. Dummy GUI Application by Codechum Admin A GUI Application is an application that has a user interface that the user can interact with. For this program, we will be simulating this behavior. First, implement another class called Checkbox which implements the Clickable interface which has only one method: public void click(). The Checkbox will have the following properties: private boolean isChecked (defaults to false upon the creation of object) private String text Additionally, it should have the following methods: the implementation of the click() method If the isChecked is currently false, this will set the isChecked to true and will then print the message "Checkbox is checked". If it is currently true, this will set the isChecked to false and will then print the message "Checkbox is unchecked". Note that the messages to be printed should have also print a new line at the end. an override of the toString() method which returns the message: "Checkbox ({text} - Clicked…arrow_forward
- Farrell, Joyce. Microsoft Visual C#: An Introduction to Object-Oriented Programming 5. Create a project for a sandwich shop. The project, named SalsSandwiches, allows a user to use a ListBox to choose a type of sandwich from at least four choices (for example, Roast beef). When the user selects a sandwich type, the program should display a second ListBox that contains at least three types of bread (for example, Whole wheat). After the user selects a bread type, the program should display a third ListBox with at least three choices for additions (for example, Lettuce). Display a message on a Label that lists all the chosen options, and make the bread and additions ListBoxes invisible. If the user makes a new selection from the first ListBox with the main sandwich choices, the bread option becomes available again, and if a new bread selection is chosen, the additions option becomes available again.arrow_forwardcode in java language : kindly include comments for better understanding.arrow_forwardC# Code: There are two A, B players playing the game. Player A is angry with him, and player B is angry with him. Both s and t include only small English letters and are of equal length. A makes the first move, then B, then A, and so on. Before the start of the game, players are familiar with the content of both the letter s and t characters. These players form one rope during the game. Initially, the character unit w is empty. In each move, the player removes any single letter from the alphabetical order in order and adds this letter any (any position) to the letter w you can add a character to any index. Please refer to the Definitions for more specifications). If in any stage of the game, the character unit w is more than 1 length and is a palindrome, the player who made the last move wins. If even after the end of the game (i.e., when both s and t are empty strings), no one can make a unit of characters w a palindrome, and then player B wins. Given the unit of the letters s, and t,…arrow_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