Java question with variables and instantiating. Create member variables of type:
ID: 3848128 • Letter: J
Question
Java question with variables and instantiating.
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
public class Boggle {
private static ArrayList<String> boggleData = new ArrayList();
private final String dataFileName = "BoggleData.txt";
private static ArrayList<String> dictionaryData = new ArrayList();
private 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();
newBoard.populateDice();
}
}
I think I'm good right up to the instantiating portion. I'm not sure where to go from there.
Explanation / Answer
Hi,
Please find below the code. I have highlighted the code lines that I have written-
public class Boggle {
private static ArrayList<String> boggleData = new ArrayList();
private final String dataFileName = "BoggleData.txt";
private static ArrayList<String> dictionaryData = new ArrayList();
private 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 = boggleData.size();
}
}
Regards,
Vinay Singh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.