Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 15, Problem 15.1PE
Program Plan Intro

Pick Four cards

Program Plan:

  • Import the required packages.
  • Create a class Myclass
    • Declare the necessary variables
    • Using start initialize the required
      • Create a new array list
      • Loop that iterates to all the 52 values into the list.
      • Create and initialize a random shuffle method.
      • Create “hbox” and add cards randomly.
      • Align the position of the cards.
      • Create a new button.
      • Add an action even to the button.
      • Shuffle randomly to place four cards.
      • Initialize the new pane.
      • Add the created items into the pane.
      • Create a scene based on the defined positions
      • Set title for the preview
      • Display the cards after refresh button is pressed.
    • Define the main method.
      • Initialize the call.

Expert Solution & Answer
Check Mark
Program Description Answer

The below program is used to pick four cards randomly by pressing refresh button:

Explanation of Solution

Program:

//import the required headers

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.image.ImageView;

import javafx.scene.layout.BorderPane;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

import java.util.ArrayList;

//define the class Myclass

public class Myclass extends Application

{

@Override

//start method gets overidden in the application class

public void start(Stage primeview) {

// create a new list

ArrayList<Integer> mylist = new ArrayList<>();

// iterate for all cards

for (int iter = 1; iter <= 52; iter++)

{

// add the values to the list

mylist.add(iter);

}

// shuffle method call

java.util.Collections.shuffle(mylist);

// new Hbox declaration

HBox my_hBox = new HBox(5);

// set the alignment to be center

my_hBox.setAlignment(Pos.CENTER);

// add card 1 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(0) + ".png"));

// add card 2 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(1) + ".png"));

// add card 3 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(2) + ".png"));

// add card 4 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(3) + ".png"));

// new button gets created

Button btRefresh = new Button("Refresh");

// action event for the button gets created

btRefresh.setOnAction(e -> {

// shuffling the card

java.util.Collections.shuffle(mylist);

// clear the contents of the hbox

my_hBox.getChildren().clear();

// add card 1 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(0) + ".png"));

// add card 2 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(1) + ".png"));

// add card 3 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(2) + ".png"));

// add card 4 to the hbox

my_hBox.getChildren().add(new ImageView("exer1/image/card/" + mylist.get(3) + ".png"));

});

// new border pane is created

BorderPane new_pane = new BorderPane();

// align the position

new_pane.setCenter(my_hBox);

// align the button position

new_pane.setBottom(btRefresh);

// add the contents to the pane

BorderPane.setAlignment(btRefresh, Pos.TOP_CENTER);

// new scene gets created

Scene n_scene = new Scene(new_pane, 250, 150);

// title of the stage is set

primeview.setTitle("Pick four cards");

// the stage gets placed in the scene

primeview.setScene(n_scene);

// stage gets displayed

primeview.show();

}

// main method

public static void main(String[] args)

{

// initilaize calls

launch(args);

}

}

Sample Output

The below output will be displayed initially:

Screenshot of initial stage

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition), Chapter 15, Problem 15.1PE , additional homework tip  1

When the refresh button is clicked the cards gets shuffled and it will be displayed as shown below:

Screenshot after rotation

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition), Chapter 15, Problem 15.1PE , additional homework tip  2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Using R language
Compare the security services provided by a digital signature (DS) with those of a message authentication code (MAC). Assume that Oscar can observe all messages sent between Rina and Naseem. Oscar has no knowledge of any keys but the public one, in the case of DS. State whether DS and MAC protect against each attack and, if they do, how. The value auth(x) is computed with a DS or a MAC algorithm. In each scenario, assume the message M = x#####auth(x). (Message integrity) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message M, and then sends M in cleartext to Naseem. Oscar intercepts the message and replaces “Mark” with “Oscar.” Will Naseem detect this in the case of either DS or MAC? If yes, how will Naseem detect it? If not, why? (Replay) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message…
I need to resolve the following....You are trying to convince your boss that your company needs to invest in a license for MS-Project (project management software from Microsoft) before beginning a systems project. What arguments would you give her?

Chapter 15 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Ch. 15.6 - Prob. 15.6.1CPCh. 15.6 - What is a functional interface? Why is a...Ch. 15.6 - Prob. 15.6.3CPCh. 15.8 - Prob. 15.8.1CPCh. 15.8 - Prob. 15.8.2CPCh. 15.9 - Prob. 15.9.1CPCh. 15.9 - Prob. 15.9.2CPCh. 15.9 - Prob. 15.9.3CPCh. 15.9 - If the following code is inserted in line 57 in...Ch. 15.10 - Prob. 15.10.1CPCh. 15.11 - Prob. 15.11.1CPCh. 15.11 - Prob. 15.11.2CPCh. 15.11 - Prob. 15.11.3CPCh. 15.11 - Prob. 15.11.4CPCh. 15.12 - How does the program make the ball appear to be...Ch. 15.12 - How does the code in Listing 15.17, BallPane.java,...Ch. 15.12 - What does the program do when the mouse is pressed...Ch. 15.12 - If line 32 in Listing 15.18, BounceBall.java, is...Ch. 15.12 - Prob. 15.12.5CPCh. 15.13 - Prob. 15.13.1CPCh. 15.13 - What would happen if map is replaced by scene in...Ch. 15.13 - Prob. 15.13.3CPCh. 15 - Prob. 15.1PECh. 15 - (Rotate a rectangle) Write a program that rotates...Ch. 15 - (Move the ball) Write a program that moves the...Ch. 15 - (Create a simple calculator) Write a program to...Ch. 15 - (Create an investment-value calculator) Write a...Ch. 15 - (Alternate two messages) Write a program to...Ch. 15 - (Change color using a mouse) Write a program that...Ch. 15 - (Display the mouse position) Write two programs,...Ch. 15 - (Draw lines using the arrow keys) Write a program...Ch. 15 - (Enter and display a string) Write a program that...Ch. 15 - (Move a circle using keys) Write a program that...Ch. 15 - Prob. 15.12PECh. 15 - (Geometry: inside a rectangle?) Write a program...Ch. 15 - Prob. 15.14PECh. 15 - Prob. 15.15PECh. 15 - (Two movable vertices and their distances) Write a...Ch. 15 - (Geometry: find the bounding rectangle) Write a...Ch. 15 - Prob. 15.18PECh. 15 - (Game: eyehand coordination) Write a program that...Ch. 15 - Prob. 15.20PECh. 15 - (Drag points) Draw a circle with three random...Ch. 15 - (Auto resize cylinder) Rewrite Programming...Ch. 15 - Prob. 15.23PECh. 15 - Prob. 15.24PECh. 15 - Prob. 15.25PECh. 15 - Prob. 15.26PECh. 15 - Prob. 15.27PECh. 15 - (Display a running fan) Write a program that...Ch. 15 - (Racing car) Write a program that simulates car...Ch. 15 - Prob. 15.30PECh. 15 - Prob. 15.31PECh. 15 - (Control a clock) Modify Listing 14.21,...Ch. 15 - (Game: bean-machine animation) Write a program...Ch. 15 - Prob. 15.34PECh. 15 - Prob. 15.35PECh. 15 - Prob. 15.36PE
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT