Createanewpackagenamedgames.utilities.
AddapublicclassnamedFileManagerthatcontainsthefollowing
methods:
public static void writeToFile(String saveState, String fileNa me) {
//TODO: Write a string to a new file synchronously }
public static void writeToFileAsync (String saveState, String fileName) {//TODO: Write a string to a new file asynchronously
}
Implement the writeToFile() method using a FileWriter in a try-with-resources block. Make sure you import theiopackage:
import.java.io.*
Implement the writeToFileAsync() method using a separate thread. Use the following code as a guide:
new Thread() { public void run(){
writeToFile(saveState fileName); }
}.start();
Inthemain()methodoftheBoardGameTesterproject,addthe following code:
FileManager.writeToFileAsync(ticTacToe.toString(), "ttt.txt");
FileManager.writeToFileAsync(connectFour.toString(), "c4.txt");
FileManager.writeToFileAsync(mastermind.toString(), "mm.txt");
The first argument in each method call should have the name you used for the corresponding Board object. Remember to import the games.utilities package!
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here