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

Cannot find symbol in Java Boggle class ArrayList of class String // stores data

ID: 3848194 • Letter: C

Question

Cannot find symbol in Java

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

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


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

public class Boggle {

    private static ArrayList<String> boggleData = new ArrayList();
    private static final String dataFileName = "BoggleData.txt";
    private static ArrayList<String> 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 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() {
    
         int i = 0;
        
            for(i=0; i<data.size(); 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
}

public interface IReadDataFile {

    public void populateData();
}

I'm getting a "cannot find symbol" under ReadDataFile in the Board class.

Im not quite sure why it's not coming together

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

Explanation / Answer

There are 2 issues in your written code

1)

In the below code

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

populatedata and getData are functions. You need to call it like this

r.populateData();
        r.getData();

2)

There is no class named Board in your code.
below lines of code won't work:

Board newBoard = new Board(data.getData(), dictionary.getData());
        newBoard.populateDice();

I have removed these and made some edits and now the code is working.

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

import java.io.*;
import java.util.ArrayList;
  
public class Boggle {
private static ArrayList<String> boggleData = new ArrayList();
private static final String dataFileName = "BoggleData.txt";
private static ArrayList<String> 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();
  

int itemCount = dictionaryData.size();

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

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() {
  
int i = 0;
  
for(i=0; i<data.size(); 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();
}
}


public interface IReadDataFile {

public void populateData();
}

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