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

Java game program. Where did I go wrong Boggledata.txt includes: D R L X E I C P

ID: 3848209 • Letter: J

Question

Java game program. Where did I go wrong

Boggledata.txt includes:

D R L X E I
C P O H S A
N H N L Z R
W T O O T A
I O S S E T
N W E G H E
B O O J A B
U I E N E S
P S A F K F
I U N H M Qu
Y R D V E L
V E H W H R
I O T M U C
T Y E L T R
S T I T Y D
A G A E E N

dictionary.txt includes a list of 61,406 words

The output should look like

Die 0: D R L X E I

looped all the way up to

Die 15: A G A E E N

as well as saying: "There are 61406 entries in the dictionary"

Theres also a "data" package that holds "BoggleData.txt" and "Dictionary.txt"

Activity

Boggle project

Boggle class

ArrayList of class String // stores data from data file with dice data

String // set to the name of input file “BoggleData.txt”

ArrayList of class String // stores data from data file with dictionary data

String // set to the name of input file “Dictionary.txt”

Instantiate an instance of class ReadDataFile passing the file name variable for file BoggleData.txt as an argument

Call method populateData on the above object

Instantiate an instance of class ReadDataFile passing the file name variable for file Dictionary.txt as an argument

Call method populateData on the above object

Instantiate an instance of class Board passing as arguments method call getData on each of the two ReadDataFile object references from above

Call method populateDice on object reference of class Board

Output to the IDE output window the number of objects in the ArrayList of type String that stores the dictionary data

core package

IBoard interface

NUMBER_OF_DICE equal to value 16

GRID equal to value 4

populateDice with return type void and an empty parameter list

shakeDice with return type ArrayList and an empty parameter list

Board class

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

IDie interface

NUMBER_OF_SIDES equal to value 6

rollDie with return type String and an empty parameter list

addLetter with a return type of void and one parameter of type String representing one of the six letters on the die

displayLetters with a return type of void and an empty parameter list

Die class

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 // stores dice data for the sides of the die

TIP: member variables should have an access level modifier of private to protect the data

Add the parameter to the ArrayList representing the letters on the die

Use an enhanced for loop to output the letter on each of the six sides of the die

inputOutput package

IReadDataFile interface

Create interface IReadDataFile

populateData with no return type and an empty parameter list

ReadDataFile class

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

Scanner // for reading the file

String // for storing the file name

ArrayList of class String // for storing the data from the file

TIP: member variables should have an access level modifier of private to protect the data

Set the member variable of type String for storing the file name equal to the parameter

Instantiate the member variable of type ArrayList

TIP: Use the IDE right click menu, Refactor, Encapsulate Fields and select just getter for the member variable of focus

TIP: this is a unique implementation, to instantiate the instance set the URL variable equal to static method call getClass().getResource()

Instantiate an instance of class File using the URL created above

TIP: pass as an argument to the constructor the reference object of the URL instance with method call .toURI()

Add to the ArrayList representing the data in the file each value read from the data file

What I have

import java.io.*;
import java.util.ArrayList;
  

public class Boggle {

    private static ArrayList boggleData = new ArrayList();
    private static final String dataFileName = "BoggleData.txt";
    private static ArrayList dictionaryData = new ArrayList();
    private static final String dictionaryFileName = "Dictionary.txt";

    public static void main(String[] args) {

        ReadDataFile data = new ReadDataFile(dataFileName);
        data.populateData();
      
        ReadDataFile dictionary = new ReadDataFile(dictionaryFileName);
        dictionary.populateData();
      
        Board newBoard = new Board(data.getData(), dictionary.getData());
        newBoard.populateDice();
     
        int itemCount = dictionaryData.size();
     
        System.out.println("There are " + itemCount + " entries in the dictionary");
    }
}

public interface IBoard {

    public static final int NUMBER_OF_DICE = 16;
    public static final int GRID = 4;

   public void populateDice();

    public ArrayList shakeDice();
}

public class Board implements IBoard {

    ArrayList boggleData;
  
    ArrayList dictionaryData;
  
    ArrayList boggleDice;

      public Board(ArrayList data, ArrayList dictionary){
  
         boggleData = data;
         dictionaryData = dictionary;
         boggleDice = new ArrayList();

         }
  
    @Override
    public void populateDice() {
     
        Die die;
        int counter = 0;

        for(int dice = 0; dice < NUMBER_OF_DICE; dice++){
          
            die = new Die();
          
            for(int side = 0; side < die.NUMBER_OF_SIDES; side++){
                die.addLetter(boggleData.get(counter).toString());
                counter++;
            }

            boggleDice.add(die);

        }
    }

    @Override
    public ArrayList shakeDice() {
      throw new UnsupportedOperationException("Not supported yet.");
    }

}

public interface IDie {

    public static final int NUMBER_OF_SIDES = 6;
   
    public String rollDie();
  
    public void addLetter(String letter);
  
    public void displayLetters();
  
}

public class Die implements IDie {
  
    private ArrayList sides = new ArrayList();

    @Override
    public String rollDie() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addLetter(String letter) {
        sides.add(letter);
    }

    @Override
    public void displayLetters() {
   
        for(String value : sides){
            System.out.print("" + value + "");
         }
    }
}

public interface IReadDataFile {

    public void populateData();
}

public class ReadDataFile implements IReadDataFile {

    private Scanner inputFile;
    private String dataFileName;
    private ArrayList data;


    public ReadDataFile(String fileName) {
       dataFileName = fileName;
       data = new ArrayList();
    }
  
     public ArrayList getData() {
    
         int i = 0;
        
            for(i=0; i                 System.out.println(data.get(i));
            }
        return data;
    }
  
  
     @Override
    public void populateData() {
        try {
            URL url = getClass().getResource("/data/" + dataFileName);
         
            File file = new File(url.toURI());
      
            inputFile = new Scanner(file);
          
            while(inputFile.hasNextLine()){
                String line = inputFile.nextLine();
                data.add(line);
            }
            inputFile.close();
        }
        catch (Exception e){
        }
          
        finally {
            if (inputFile != null)
            inputFile.close();
        }
    }
}

    public static void main(String args[]){
        ReadDataFile r = new ReadDataFile("BoggleData.txt");
        r.populateData;
        r.getData
}

Activity

Boggle project

Boggle class

Create member variables of type:

ArrayList of class String // stores data from data file with dice data

String // set to the name of input file “BoggleData.txt”

ArrayList of class String // stores data from data file with dictionary data

String // set to the name of input file “Dictionary.txt”

Method main() should:

Instantiate an instance of class ReadDataFile passing the file name variable for file BoggleData.txt as an argument

Call method populateData on the above object

Instantiate an instance of class ReadDataFile passing the file name variable for file Dictionary.txt as an argument

Call method populateData on the above object

Instantiate an instance of class Board passing as arguments method call getData on each of the two ReadDataFile object references from above

Call method populateDice on object reference of class Board

Output to the IDE output window the number of objects in the ArrayList of type String that stores the dictionary data

core package

IBoard interface

Add constant fields:

NUMBER_OF_DICE equal to value 16

GRID equal to value 4

Add method signatures:

populateDice with return type void and an empty parameter list

shakeDice with return type ArrayList and an empty parameter list

Board class

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

IDie interface

Add constant field:

NUMBER_OF_SIDES equal to value 6

Add method signatures:

rollDie with return type String and an empty parameter list

addLetter with a return type of void and one parameter of type String representing one of the six letters on the die

displayLetters with a return type of void and an empty parameter list

Die class

Update the class so that it implements interface IDie

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 // stores dice data for the sides of the die

TIP: member variables should have an access level modifier of private to protect the data

Implement method addLetter; the method should:

Add the parameter to the ArrayList representing the letters on the die

Implement method displayAllLetters; the method should:

Use an enhanced for loop to output the letter on each of the six sides of the die

inputOutput package

IReadDataFile interface

Create interface IReadDataFile

Add method signature:

populateData with no return type and an empty parameter list

ReadDataFile class

Update the class so that it implements interface IReadDataFile

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 variables using the specified data types:

Scanner // for reading the file

String // for storing the file name

ArrayList of class String // for storing the data from the file

TIP: member variables should have an access level modifier of private to protect the data

Add a custom constructor that receives one parameter of type String representing the name of the data file to read; it should do the following:

Set the member variable of type String for storing the file name equal to the parameter

Instantiate the member variable of type ArrayList

Add a getter for the ArrayList member variable that stores the data read from the data file

TIP: Use the IDE right click menu, Refactor, Encapsulate Fields and select just getter for the member variable of focus

Implement method populateData; it should do the following:Instantiate an instance of Java API class URL passing as an argument member variable representing the file name of the data file

TIP: this is a unique implementation, to instantiate the instance set the URL variable equal to static method call getClass().getResource()

Instantiate an instance of class File using the URL created above

Initialize member variable of type Scanner based on the File instance created above

TIP: pass as an argument to the constructor the reference object of the URL instance with method call .toURI()

Loop through the data file until the end

Add to the ArrayList representing the data in the file each value read from the data file

Explanation / Answer

Here is your corrected code : Giving you expected output . Compare your code with these to get help :

import java.util.ArrayList;

public class Board implements IBoard {
   ArrayList<String> boggleData;

   ArrayList<String> dictionaryData;

   ArrayList<Die> boggleDice;

   public Board(ArrayList<String> data, ArrayList<String> dictionary) {

       boggleData = data;
       dictionaryData = dictionary;
       boggleDice = new ArrayList<Die>(16);
   }

   @Override
   public void populateDice() {

       Die die;
       int counter = 0;
       for (int dice = 0; dice < NUMBER_OF_DICE; dice++) {
           die = new Die();
           String[] data = boggleData.get(dice).toString().split(" ");
           for (int side = 0; side < die.NUMBER_OF_SIDES; side++) {
               die.addLetter(data[side]);
           }
           System.out.print("Die "+ dice + ": ");
           die.displayLetters();
           System.out.println();
           counter++;
           boggleDice.add(die);
       }
   }

   @Override
   public ArrayList<String> shakeDice() {
       throw new UnsupportedOperationException("Not supported yet.");
   }

}

import java.io.*;
import java.util.ArrayList;

public class Boggle {
   private static ArrayList<String> boggleData = new ArrayList<String>();
   private static final String dataFileName = "BoggleData.txt";
   private static ArrayList<String> dictionaryData = new ArrayList<String>();
   private static final String dictionaryFileName = "Dictionary.txt";

   public static void main(String[] args) {

       ReadDataFile data = new ReadDataFile(dataFileName);
       data.populateData();
       boggleData.addAll(data.getData());

       ReadDataFile dictionary = new ReadDataFile(dictionaryFileName);
       dictionary.populateData();
       dictionaryData.addAll(dictionary.getData());

       Board newBoard = new Board(boggleData, dictionaryData);
       newBoard.populateDice();

       System.out.println(" There are " + dictionaryData.size()
               + " entries in the dictionary");
   }
}

import java.util.ArrayList;

public class Die implements IDie {
  
private ArrayList<String> sides = new ArrayList<String>();
@Override
public String rollDie() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void addLetter(String letter) {
sides.add(letter);
}
@Override
public void displayLetters() {

for(String value : sides){
System.out.print("" + value + " ");
}
}
}

import java.util.ArrayList;

public interface IBoard {

   public static final int NUMBER_OF_DICE = 16;
   public static final int GRID = 4;

   public void populateDice();

   public ArrayList shakeDice();
}

public interface IDie {

public static final int NUMBER_OF_SIDES = 6;

public String rollDie();
  
public void addLetter(String letter);
  
public void displayLetters();
  
}

public interface IReadDataFile {

public void populateData();
}

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;

public class ReadDataFile implements IReadDataFile {
   private Scanner inputFile;
   private String dataFileName;
   private ArrayList<String> data;

   public ReadDataFile(String fileName) {
       dataFileName = fileName;
       data = new ArrayList<String>();
   }

   public ArrayList<String> getData() {
       return data;
   }

   @Override
   public void populateData() {
       try {
           //URL url = this.getClass().getResource(dataFileName);

           File file = new File(dataFileName);

           inputFile = new Scanner(file);

           while (inputFile.hasNextLine()) {
               String line = inputFile.nextLine();
               data.add(line);
           }
           inputFile.close();
       } catch (Exception e) {
       }

       finally {
           if (inputFile != null)
               inputFile.close();
       }
   }

   public static void main(String args[]) {
       ReadDataFile r = new ReadDataFile("BoggleData.txt");
       r.populateData();
       r.getData();
   }
}

Please don't forget to give me upvote for this . This will help me alot

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