Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me get this sample output? This is the output that I want! This is what should be put into this assig This

Can someone help me get this sample output?

This is the output that I want! This is what should be put into this assig

image text in transcribedThis is the output that I want!

image text in transcribed

This is what should be put into this assig

The Tester code is downhere

import java.io.*; import java.util.Scanner; /* * MazeTester.java * * Requires: Maze.java */ public class MazeTester { private static char[][] maze; private static int width, height; private static final Scanner KBD = new Scanner(System.in); private static final PrintStream OUT = System.out; /* * program for testing the Maze class: * 1. get maze file name, width and height from user * 2. make the maze 2-D char array * 3. read the maze from the file * 4. create a Maze object with the maze * 5. get the start point from the user * 6. solve the maze (if possible), tell user what happened */ public static void main(String[] args) { final int ERROR=1; String fName = null; int r=0, c=0; // maze coordinates for entrance try { // get maze file name from user // abort the program if any input is not valid OUT.print("File name? "); fName = getString("\tInvalid file name, bye!"); } catch (IOException e) { OUT.println(e.getMessage()); System.exit(ERROR); } try (Scanner fileReader = new Scanner(new File(fName))) { // get maze file name, width and height from user OUT.print("Maze width? "); width = getDimension("\tInvalid width, bye!"); OUT.print("Maze height? "); height = getDimension("\tInvalid height, bye!"); // make the maze 2-D char array maze = new char[height][width]; // read the maze from the file readMaze(fileReader); // showMaze(); // create a Maze object with the maze Maze solver = new Maze(maze); // get the start point from the user // abort the program if any input is not valid OUT.print("OK, maze is loaded ... where is the entrance (row# col#)? "); r = getCoordinate(width, "\tInvalid row coordinate, bye!"); c = getCoordinate(height, "\tInvalid column coordinate, bye!"); // solve the maze (if possible), tell user what happened if (solver.escape(r-1, c-1)) { OUT.println("Yay, I made it through the maze!!!"); } else { OUT.println("Help, there's no way out!!!"); } // end if ... else } catch (IOException e) { OUT.println(e.getMessage()); System.exit(1); } // end try...catch } // end main /* * gets a String from the user and validates it * as a non-null, non-empty String before returning it * throws an IOException with the given error String * if invalid input */ private static String getString(String error) throws IOException { String result = KBD.nextLine(); if (result == null || result.length() == 0) { throw new IOException(error); } return result; } // end getString /* * gets a dimension from the user and validates it * as a positive integer before returning it * throws an IOException with the given error String * if invalid input */ private static int getDimension(String error) throws IOException { int result = 0; if (KBD.hasNextInt()) { result = KBD.nextInt(); if (result  dimension) { throw new IOException(error); } } else { throw new IOException(error); } return result; } // getCoordinate /* * loads the maze using the given Scanner to the input file */ private static void readMaze(Scanner reader) throws IOException { int rowIndex = 0; while (reader.hasNextLine() && rowIndex  

image text in transcribed

Sample Run (user input in color) Filename? mazel 9x9. txt Maze width?9 Maze height? 9 OK, maze is loaded where is the entrance (row# cols)? 5 4 Yay, I made it through the maze

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

Step: 3

blur-text-image

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago