Question: Can someone please fix my edit retrieveFromFile and saveToFile method so that they fit this criteria. The way they currently are they have 0 functionality.
Can someone please fix my edit retrieveFromFile and saveToFile method so that they fit this criteria. The way they currently are they have functionality. It should not be a printout to console.
Itemized Part requirements of user interaction
The user should be able to save a current game to file, to
finish it later by retrieving it from file. As such, the methods saveToFile and retrieveFromFile should be added
to the game class. The file extension for the game file
should be gam or tet
When saving a game to a file, the user must be able to enter
a unique file name. The program should add the extension.
You must be able to retrieve a game back from a gam
or tet file using a GUI Interface to select file JFileChooser
public void saveToFile
String optionsOk"Cancel";
String titleJOptionPane.showInputDialogPut your name ;
JFileChooser fileChooser new JFileChooserFileSystemViewgetFileSystemView;
fileChooser.showSaveDialogfileChooser;
try PrintWriter writer new PrintWriternew FileWritertitle tar"
Write game state to file
writer.printlnrows;
writer.printlncols;
writer.printlnnumBrickTypes;
writer.printlnstate;
writer.printlnscore;
Write background array to file
for int i ; i rows; i
for int j ; j cols; j
writer.printbackgroundij;
writer.println;
Write fallingBrick details to file
writer.printlngetRows;
writer.printlngetCols;
writer.printlnfetchBoardPositionint row,;
writer.printlnfallingBrickgetColorNumber;
writer.printlnArraystoStringfallingBrickgetPosition;
writer.printlnfallingBrickgetOrientation;
writer.printlngetScore;
writer.close;
catch IOException e
eprintStackTrace;
public void retrieveFromFile
String fNamenull;
File fileConnection new FilefName;
try
Scanner inScann new ScannerfileConnection;
rows inScann.nextInt;
cols inScann.nextInt;
background new introwscols;
forint row ; row rows;row
forint col ; col cols;col
backgroundrowcol inScann.nextInt;
catchException e
System.err.printError occurred during retrieve from file ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
