Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to get a program to work but there are a couple of compile errors th

ID: 3918995 • Letter: I

Question

I am trying to get a program to work but there are a couple of compile errors that I cannot figure out. Could you fix them so the program can run and compile properly. Thank you!

import javafx.application.Application;

import javafx.event.ActionEvent;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.BorderPane;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

public class blackjack6 extends Application {

   public void start(Stage primaryStage) throws Exception{

  

   DeckOfCards deck = new DeckOfCards();

  

   HBox text = new HBox();

Label label1 = new Label("Let's play some black jack!");

text.getChildren().addAll(label1);

  

   HBox cards = new HBox();

Image img = new Image("1.png");

ImageView imgView = new ImageView(img);

Image img0 = new Image("b1fv.png");

ImageView imgView0 = new ImageView(img0);

Image img1 = new Image("b1fv.png");

ImageView imgView1 = new ImageView(img1);

Image img2 = new Image("b1fv.png");

ImageView imgView2 = new ImageView(img2);

Image img3 = new Image("b1fv.png");

ImageView imgView3 = new ImageView(img3);

cards.getChildren().addAll(imgView, imgView0, imgView1, imgView2,imgView3);

   HBox hb = new HBox(50);

  

   Button btn1 = new Button("Shuffle");

   Button btn2 = new Button("Deal");

   hb.getChildren().addAll(btn1,btn2);

  

   BorderPane pane = new BorderPane();

   pane.setTop(text);

   pane.setCenter(cards);

pane.setBottom(hb);

  

   btn2.setOnAction((clicked) -> {System.out.println("Hit me");});

   btn1.setOnAction((clicked) -> {deck.shuffle();});

  

Scene scene = new Scene(pane, 360, 150);

primaryStage.setTitle("Card Game");

primaryStage.setScene(scene);

primaryStage.show();

   }

  

   public static void main(String[] args){

   Application.launch(args);

   }

   public class DeckOfCards<Card> {

   int[] deck;

   int next_card = 0;

  

   public static final int SIZE_OF_DECK = 52;

   public DeckOfCards(){

   this(1);

   }

  

   public DeckOfCards(int num_decks){

   this.deck = new int[num_decks*DeckOfCards.SIZE_OF_DECK];

  

   for(int i = 0; i<this.deck.length; i++){

   int k = i%DeckOfCards.SIZE_OF_DECK;

   this.deck[i] = k;

   }

  

   }

   public void shuffle(){

   for(int i = 0; i<this.deck.length; i++){

   int j = (int)(Math.random()*this.deck.length);

   int temp = this.deck[i];

   this.deck[i] = this.deck[j];

   this.deck[j] = temp;

   }

   this.next_card = 0;

   System.out.println("Shuffled");

  

   }

  

   public Card nextCard(){

   return new Card(this.deck[this.next_card++]);

   }

  

   public boolean hasNext(){

   return this.next_card<this.deck.length;

   }

  

  

   }

}

Explanation / Answer

Hi Sir, couple of updates are required in this program:-

1. Make sure you have the following 3 classes in the same working directory in different Java files - blackjack6.java, DeckOfCards.java, Card.java [each of them should be in its own class file]

2. In blackjack6.java, make sure the images that you have mentioned, 1.png, b1fv.png, etc should be in the same folder where the java classes are there as its unable to locate these images when launch(args) executes.

3. In DeckOfCards.java, the nextCard() method creates new Card object and return it

return new Card(this.deck[this.next_card++]);

Make sure the Card class has this constructor provided with valid args passed to it.

Let me know in case of any clarifications required. Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote