Big Java Late Objects
Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 13, Problem 7PP
Program Plan Intro

Escaping a Maze

Program plan:

Filename: “Maze.java”

This program file is used to define a class “Maze”. In the code,

  • Import the required packages.
  • Define a class “Maze”.
    • Define the class members “maze[][]”, “width”, “height”.
    • Define the constructor “Maze()”.
      • Initialize the class members.
    • Define the method “escape()”.
      • If the condition “isExit(i,j)” is true,
        • Return “true”.
          • If the array element “maze[][]” is not equal to space,
            • Return “false”.
          • If the condition “i < 0 || j < 0 || i >= height || j >= width” is true,
            • Return “false”.
          • Set “maze[i][j]” equal to “.”.
          • If “escape(i-1,j)” is true,
            • Set “maze[i][j]” equal to space.
            • Return “true”.
          • If “escape(i+1,j)” is true,
            • Set “maze[i][j]” equal to space.
            • Return “true”.
          • If “escape(i,j-1)” is true,
            • Set “maze[i][j]” equal to space.
            • Return “true”.
          • If “escape(i,j+1)” is true,
            • Set “maze[i][j]” equal to space.
            • Return “true”.
          • Set “maze[i][j]” equal to “ ”.
          • Return “false”.
    • Define a method “isExit()”.
      • Return the value.

Filename: “MazeDemo.java”

This program file is used to define a class “MazeDemo”. In the code,

  • Define a class “MazeDemo”.
    • Define the “main” method.
      • Create a character array “m”.
      • Define the object “maze” of “Maze”.
      • Call the method “escape()” and print the result.
      • Print the expected value.
      • Call the method “escape()” and print the result.
      • Print the expected value.

Blurred answer
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education