/* * P 794 The 24-point game is to pick any 4 cards from 52 cards, as shown in Figure 20.19. Note that the Jokers are excluded. Each card represents a number. An Ace, King, Queen, and Jack represent 1, 13, 12, and 11, respectively. You can click the Shuffle button to get four new cards. Enter an expression that uses the four numbers from the four selected cards. Each number must be used once and only once. You can use the operators (addition, subtraction, multiplication, and division) and parentheses in the expression. The expression must evaluate to 24. After entering the expression, click the Verify button to check whether the numbers in the expression are currently selected and whether the result of the expression is correct. Display the verification in a label before the Shuffle button. Assume that images are stored in files named 1.png, 2.png, . . . , 52.png, in the order of spades, hearts, diamonds, and clubs. So, the first 13 images are for spades 1, 2, 3, . . . , and 13. */ public class Exercise_19 extends Application {@Override public void start(Stage primaryStage) { ArrayList deck = new ArrayList<>(); BorderPane borderPane = new BorderPane(); TextField expressText = new TextField(); Button verifyButton = new Button("Verify"); Button shuffleButton = new Button("Shuffle"); expressText.setPrefColumnCount(4); HBox hBox = new HBox(10); hBox.getChildren().addAll(new Label("Enter an expression:"), expressText); hBox.getChildren().addAll(verifyButton, shuffleButton); hBox.setAlignment(Pos.BOTTOM_RIGHT); borderPane.setBottom(hBox); // Create the cards we'll be using for the deck for(int i = 0; i < 52; i++) { deck.add(i); } final AtomicReference result = new AtomicReference<>("go."); // Shuffle the deck Collections.shuffle(deck); // Button to shuffle the deck of cards shuffleButton.setOnAction(e -> {Collections.shuffle(deck);}); HBox center = new HBox(10); // First card to be displayed Card card1 = new Card(deck.get(0)); center.getChildren().add(card1); // Second card to be displayed Card card2 = new Card(deck.get(1)); center.getChildren().add(card2); // Third card to be displayed Card card3 = new Card(deck.get(2)); center.getChildren().add(card3); // Fourth card to be displayed Card card4 = new Card(deck.get(3)); center.getChildren().add(card4); LinkedList
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
Students Have Also Explored These Related Databases Questions!