Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Need Help with this project! There are 3 classes posted below! /** * We need to set both field and exposed data, * * but MineField doesn't give us a...

Need Help with this project! There are 3 classes posted below!

1.

/**

 * We need to set both field and exposed data,

 *

 * but MineField doesn't give us a way to set both from outside the class.

 *

 * We also need to access the field and exposed array to save. But the protected

 * data is not accessible from outside of MineField.

 *

 * If only there were a way to to extend the MineField class to allow this.

 *

 * I'm leaving this class relatively wide open. If these hints are not enough,

 * look at the MineFieldIOTest.java unit test that I gave you to get you started

 * with how I constructed my solution.

 *

 * You are free to do another way, and only the MineFieldFileIOTests are used on

 * WebCat. (But make sure this class still compiles, even if you don't follow

 * the exact approach that I used.)

 *

 * @author Russell DiMiceli

 * @version 1

 *

 */

// @todo - write this class as needed

public class MineFieldIO {

   // @todo - as you wish

}

2./**

 * Class to handle loading and saving of data

 *

 * You must write 4 methods

 *

 * loadMineField - loads mine field definition

 *

 * saveMineField - saves minefield

 *

 * Here the only concern is loading/saving a mine field definition file where -1

 * denotes a mine, and any non-negative number is safe.

 *

 * saveGame - saves the entire game state

 *

 * loadGame - loads the game state

 *

 * For a game we need both the mines and the exposed array data. Unfortunately

 * the given MineField class (which you cannot change) does not provide a way to

 * set that.

 *

 * Take a look at documentation for MineFieldIO and see if you can think of a

 * way to use that shell class to help you.

 *

 *

 * @author <student>

 * @version 0

 *

 */

public class MineFieldFileIO {

   /**

    * Saves a mine field definition to a file (You decide the format)

    *

    * @param mf

    *           - reference to a mine field

    * @param fileName

    *           - string to path to minefield

    * @return true if successfully saved, false otherwise

    *

    */

   public static boolean saveMineFile(MineField mf, String fileName) {

       // @todo - fix this

       return false;

   }

   /**

    * Reads the minefield definition from a file format of your choosing.

    *

    * A complete minefield with initialized hints and exposed array should be

    * returned.

    *

    * Throws a MineFieldException if the file is opened, but the data is

    * invalid.

    *

    * Valid games should have at least 1 mine, and at least one empty cell.

    *

    * @param fileName

    *           - string to path to minefield

    * @return valid instance to minefield instance or null if file has

    *        IOException

    * @throw invalid MineFieldException if data in file is invalid for any

    *       reason other than IOException

    */

   public static MineField readMineFile(String fileName) {

       // @todo - fix this

       return null;

   }

   /**

    *

    * Saves the current game state to file including both minefield and current

    * exposed array information.

    *

    * The format is of your choosing.

    *

    * @param mineField

    *           - reference to a mine field

    * @param fileName

    *           - string to path to minefield

    * @return true if successfully saved, false otherwise

    *

    */

   public static boolean saveMineSweeperGame(MineField mineField,

           String fileName) {

       // @todo - fix this

       return false;

   }

   /**

    * Reads the saved game state, both field and exposed status, from a file

    * format of your choosing.

    *

    * A complete minefield with initialized hints and exposed array should be

    * returned.

    *

    * Throws a MineFieldException if the file is read, but the data is invalid.

    *

    * Valid games should have at least 1 mine, at least one empty cell, and at

    * least 1 unexposed cell that is either a 0 or hint.

    *

    * @param fileName

    *           - string to path to minefield

    * @return valid instance to minefield instance or null if file has

    *        IOException

    * @throw invalid MineFieldException if data is invalid for any reason other

    *       than a file IOException

    */

   public static MineField readMineSweeperGame(String fileName) {

       // @todo - fix this

       return null;

   }

}

3./**

 *

 * This should be a runtime exception that contains a message saying what the

 * error was.

 *

 * @author <student>

 * @version 0

 *

 */

public class MineFieldException {

   // @todo - need to construct with message

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question