Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***In Java*** I am trying to loop through a file until the end is reached but I am having trouble. here is my code:( Bolded

***In Java*** I am trying to loop through a file until the end is reached but I am having trouble.

here is my code:(Bolded code is the loop i need help with)

public class BoardGame {

private int board_length; private int board_width; // private Snake theSnake; private String[][] matrix; private String buffer = null;

public BoardGame(String boardFile) { MyFileReader in; in = new MyFileReader(boardFile); int value1 = in.readInt(); int value2 = in.readInt(); board_length = in.readInt(); board_width = in.readInt(); int intialRow = in.readInt(); int intialCol = in.readInt(); // theSnake = new Snake(initialRow, initialCol); matrix = new String[board_length][board_width]; for (int i = 0; i < board_length; i++) { for (int j = 0; j < board_width; j++) { matrix[i][j] = "empty"; } }

while (in.hasNextLine()){ matrix[in.readInt()][in.readInt()] = in.readString(); }

} However this is not working. the format of the file after the first 6 lines is int,int,string,int,int,string and so on.

MyFileReader is a BufferedReader is that makes any difference.

Thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

Why do valuation models lend themselves to "playing with mirrors"?

Answered: 1 week ago