[Solved]-Question 1 Loads Story Current Room Bookmark File Method Assumes First Line File Containin Q37180667
Question 1:
Loads the story and the current room from a bookmark file. Thismethod assumes that the first
* line of the file, containingConfig.MAGIC_BOOKMARK, has already been read from the Scanner.
*
* The format of a bookmark file is as follows:
* Line No: Contents
* 1: Config.MAGIC_BOOKMARK
* 2: Story filename
* 3: Current room id
*
* As an example, the following contents would loadthe story Goldilocks.story and set the
* current room to id 7.
*
* #!BOOKMARK
* Goldilocks.story
* 7
*
* Your method should not duplicate the code fromthe parseFile method. It must use the
* parseFile method to populate the rooms and transmethods based on the contents of the story
* filename read and trimmed from line 2 of thefile. The value of for the cell at index 0 of
* curRoom is the trimmed value read on line 3 ofthe file.
*
* @param sc The Scanner objectbuffering the input file to read.
* @param rooms The ArrayListstructure that will contain the room details. A parallelArrayList
* trans.
* @param trans The ArrayListstructure that will contain the transition details. A parallel
* ArrayList to rooms.
* @param curRoom An array of atleast length 1. The current room id will be stored in the cell
* at index 0.
* @return false if there is aparsing error. Otherwise, true.
*/
public staticboolean parseBookmark(Scanner sc,ArrayList<String[]> rooms,
ArrayList<ArrayList<String[]> > trans,
String[] curRoom) {
return true;
}
Question 2:
Returns the next room id, selected randomly based on thetransition probability weights.
*
* If curTrans is null or the total sum of all theprobability weights is 0, then return null.
* Use Integer.parseInt to convert the Strings atindex Config.TRAN_PROB of the transition
* String array to integers. If there is aNumberFormatException, return null.
*
* It is important to follow the specifications ofthe random process exactly. Any deviation may
* result in failed tests. The random transitionwork as follows:
* – Let totalWeight be the sum of the all thetransition probability weights in curTrans.
* – Draw a random integer between 0 and totalWeight- 1 (inclusive) from rand.
* – From the beginning of the ArrayList curTrans,start summing up the transition probability
* weights.
* – Return the String at index Config.TRAN_ROOM_IDof the first transition that causes the
* running sum of probability weights to exceed therandom integer.
*
* See parseStory method for the details of thetransition String array.
*
* @param rand The Random classfrom which to draw random values.
* @param curTrans The ArrayListstructure that contains the transition details.
* @return The room id that wasrandomly selected if the sum of probabilities is greater than0.
* Otherwise, return null. Also, return null ifthere is a NumberFormatException.
*/
public static StringprobTrans(Random rand, ArrayList<String[]> curTrans) {
return null;
}
Expert Answer
Answer to Question 1: Loads the story and the current room from a bookmark file. This method assumes that the first * line of the … . . .
OR

