Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Shuffling Cards - Write in Java Write a program that displays four cards randomly selected from a deck of 52 if the Refresh button

Programming Shuffling Cards - Write in Java

Write a program that displays four cards randomly selected from a deck of 52 if the Refresh button is clicked, shown below. The card image files are named 1.png, 2.png 52.png and stored in the image/card directory. All four cards are distinct and selected randomly. The card files are provided in Blackboard.

Hint: You can select random cards by storing the numbers 1-52 to an array list, perform a random shuffle learned in Section 11.12, and use the first four numbers in the array list as the file names for the image. The other way is to use the static shuffle method in the java.util.Collections class, for example: java.util.Collections.shuffle(list) where list is an array list.

Directions

Create a class named CardRefreshButton extends Application.

Create a new array list, then use a for loop and add() method to add 52 cards to the list.

Revoke shuffle() method for the list to shuffle the cards.

Create an instance of HBox and add four card images by using getChildren().add() method. Make sure specify image file path and use array lists get() method to get four card image files.

Create a Button and labeled with Refresh

Create and register an event handler.

To handle event: once the button is clicked, call shuffle() method to shuffle the cards, then clear previous images by using getChildren.clear() method, and use add() to add four card images.

Create a new BorderPane to set up layout for the images and button.

Create a scene with a specific size.

Set title to Shuffling cards and display the stage.

The output should look like the screen below.

Provide appropriate Java comments.

image text in transcribed

Grading Rubric

Task

Points

Create user interface using Scene, Pane and Stage

2

Use array list and a for loop to hold 52 cards

2

Shuffle cards by using random selection or static shuffle method

2

Create a HBox and use appropriate methods to add images and setup layout

3

Create Refresh button and handler

2

Use methods to shuffle, clear and add images correctly to handle button click event

3

Use BorderPane correctly to setup layout

2

The output for Shuffling Cards is correct and looks like the sample screen

2

Total

18

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago