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

Question for Java game I have a \"Board\" Class. How do I: TIP: Use Netbeans rig

ID: 3846831 • Letter: Q

Question

Question for Java game

I have a "Board" Class. How do I:

TIP: Use Netbeans right click menu, Insert Code, Implement Method to have the IDE generate the methods for you; you will replace the throw exception statements with the source code you write

ArrayList of class String // stores dice data

ArrayList of class String // stores dictionary data

ArrayList of class Die // stores 16 game dice

Set the member variable of type ArrayList of class String that stores the Boggle data equal to the associated parameter in the method signature

Set the member variable of type ArrayList of class String that stores the dictionary data equal to the associated parameter in the method signature

Instantiate the member variable of type ArrayList of class Die.

Declare a variable of type class Die

Declare and initialize a variable of type int to serve as a counter to access the data in the member variable of type ArrayList of type String storing the Boggle data

Instantiate the instance of class Die using the default no-argument constructor

Add each of the 6 letters to the Die ArrayList representing the die letters by calling method addLetter in class Die

Display the letters of each die by calling method displayLetters() in class Die on a separate row

Add each die instance to the ArrayList declared specifically for class Die

Update the class so that it implements interface IBoard

TIP: Use Netbeans right click menu, Insert Code, Implement Method to have the IDE generate the methods for you; you will replace the throw exception statements with the source code you write

Add member variable of type:

ArrayList of class String // stores dice data

ArrayList of class String // stores dictionary data

ArrayList of class Die // stores 16 game dice

Add a custom constructor with two parameters of type ArrayList of class String; it should do the following

Set the member variable of type ArrayList of class String that stores the Boggle data equal to the associated parameter in the method signature

Set the member variable of type ArrayList of class String that stores the dictionary data equal to the associated parameter in the method signature

Instantiate the member variable of type ArrayList of class Die.

Implement method populateDice; the method should do the following:

Declare a variable of type class Die

Declare and initialize a variable of type int to serve as a counter to access the data in the member variable of type ArrayList of type String storing the Boggle data

Loop through the 16 dice (use the constant NUMBER_OF_DICE as your terminating condition):

Instantiate the instance of class Die using the default no-argument constructor

For each Die instance, loop through the six sides of the die (use the constant NUMBER_OF_SIDES as your terminating condition):

Add each of the 6 letters to the Die ArrayList representing the die letters by calling method addLetter in class Die

Display the letters of each die by calling method displayLetters() in class Die on a separate row

Add each die instance to the ArrayList declared specifically for class Die

Explanation / Answer

//Board.java

import java.util.ArrayList;


public class Board implements IBoard {
// stores the letter data from the data file
ArrayList<String> boggleData;
  
// stores the dictionary data
ArrayList<String> dictionaryData;
  
// collection of dice
ArrayList<Die> boggleDice;
  
public Board(ArrayList<String> diceData, ArrayList<String> dictionary){
  
boggleData = diceData;
dictionaryData = dictionary;
boggleDice = new ArrayList<Die>();
}
  
  
@Override
public void shakeDice(){
throw new UnsupportedOperationException("Not supported yet."); // To change the body of generated methods, choose Tools | Templates.
  
}

@Override
public void populateDice() {
  
Die die;// new data type Die
int counter = 0;
  
// Create an instance of class String, locally called value
//loop through the contents of container names letters
// loop 16 times for die
for(int dice = 0; dice < NUMBER_OF_DICE; dice++){
  
// create instance of die
die = new Die();
  
// add 6 times of the array list to populate the die sides
for(int side = 0; side < die.NUMBER_OF_SIDES; side++){
  
die.addLetter(boggleData.get(counter).toString());
counter++;
}
  
// temp
System.out.print("Die " + dice + ": ");
die.displayLetters();
System.out.println();
  
boggleDice.add(die);

}
}
  
}

=========================================================================

//Die.java
import java.util.ArrayList;

public class Die implements IDie{
  
private ArrayList<String> letters = new ArrayList<String>(); // stores dice data for the sides of the die

@Override
// Enhanced for loop to output each letter on ech of the six sides of die
public void displayLetters() {
  
for(String value : letters){
System.out.print("" + value +" ");
}
}

@Override
// Add parameter to the ArrayList
// represnting the letters on the die
public void addLetter(String letter) {
  
letters.add(letter);
}

@Override
public String rollDie() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
  
  
  
}

======================================================================

//IBoard.java
public interface IBoard {
  
// each board has 16 dice in 4x4 layout
public static final int NUMBER_OF_DICE = 16;
public static final int GRID = 4;
  
// This method will invoke the rollDie method for each of the 16 dice in the game
public void shakeDice();
  
// This method will add the data to the dice
public void populateDice();
}

=============================================================================

//IDie.java
public interface IDie {
  
// this is a constant
public static final int NUMBER_OF_SIDES = 6;
  
public void displayLetters(); // displays the letters in the BoggleData txt file
  
// this method will add a letter to the die
public void addLetter(String letter);
  
// this method will return the current letter of the die
public String rollDie();
}

===============================================================================

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