Question

Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you......

Need help!! Java Eclipse

Please provide the screenshot of output of code as well.

thank you...

PROGRAM 1 –Linear Data Structure Implementation (Due date: March 5th, 2019, 5% Grade Points)

Given the starting point in a maze, you are to find and mark a path out of the maze which is represented by a 30x30 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically or horizontally in any direction that contains a 0; you may not move into a square with a 1. If you move into the square with an E, you have exited the maze. If you are in a square with 1s on three sides, you must go back the way you came and try another path. You may not move diagonally. For this program, use can ONLY use a single linked list.

Program Requirements: Your program should use single linked list ONLY for finding the path.

Input of program: Input is the following array of characters (1s, 0s, and E) from an ASCII text data file (maze.txt); as follows:

E0001110000000100100

11100011101110001111

11111000101000111000

00001110101100010010

01011000101111000110

00001110000110011110

11011100110110111000

00011110110111111101

01011011110110100001

01000000000110110111

11011011010010000000

01010010011000101011

01111000101110101110

00001110000111011001

01101011101101000011

11000110100111011010

01110000100100110011

11010111110110000000

01110100011000111110

00011001000011100010

Each data line consists of one row of maze. Starting points (i.e. a row, column pair) in the maze will be input from the keyboard.         

Output of program: Echo print the maze complete with numbered rows and columns prior to asking the user for their starting point. For each entry into the maze, print the complete maze with a S in the starting point followed by the words ‘I am free’ if you have found a path out of the maze or the words ‘Help, I am trapped’ if you cannot. Your output could be in two formats:

Print the path (by using a series of pluses (+)) you took through the maze should one be found OR Print the path as a single linked list. A program heading in the following format should begin your program:

                       

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Program : Maze puzzle 30X30

Steps follows :-

1 - Creating txt file for maze called mazefile.txt
2 - establish 30 X 30 array to hold maze
3 - read maze info from file and call print method
4 - for loops to loop through 2d array reading through sc.next && sc.next line
5 - Try and catch block For exception handling printarray()
6 - praintarray() print the location 
7 - Asking from the user to enter in the starting location
8 - Switch cases confirm the location and check the condition 
9 - having interface Stack for 
           1- Inset a new iteminto the stack
           2- X the item to insert
           2- Function for PUSH,POP,TOP,IsEmpty,and Object(stack)

10 - Operation of Stack function

  • Push();
    Remove the most recently inserted item from the stack.
    exception UnderflowException if the stack is empty.
  • pop();
     Get the most recently inserted itemin the stack.
     Does not alter the stack.
     return the most recently inserted item in the stack.
     exception UnderflowException is fht estack is empty.
     
  • top();
    Return and remove the most recently inserted itemfrom the stack.
    return the most recently inserted item in the stack.
    throws Underflow if the stack is empty.
    
    
    
  • move();
    Return to original position and move
     position up, down , left and right*/
  • isEmpty();
     Test if the stack is logically empty.
     return true if empty, false otherwise.
     X
    
    

Program is as follows :-

 
 
import java.io.*;
import java.util.*;
public class mazeGame {




static String[][]maze;
public static void main(String[] args)
    {
maze=new String[30][30];
maze=fillArray("mazefile.txt");
    }
public static String[][]fillArray(String file)
    {
     maze = new String[30][30];
        
        try{
        Scanner sc = new Scanner(new File(file));
        
        for(int row = 0; row < 30; row++)
        {
            for(int col = 0; col < 30; col++)
            {
                maze[row][col] = sc.next();
            }
            sc.nextLine();
        }
printArray();
       }
        catch(FileNotFoundException fe)
        {
        System.out.println("Error: file mazefile.txt not found!");
        }
     return maze;
    }
public static void printArray()
        {
    System.out.println();
    for(int row=0;row<30;row++)
    {
        for(int col=0;col<30;col++)
        {
            System.out.print(maze[row][col]+" ");
        }
        System.out.println();
    }


}

public void location()
{

    System.out.println("Please enter from the Matrix location S.");
Scanner StartingPoint  = new Scanner(System.in);
String index = StartingPoint.nextLine();
String[] indices = index.split(" ");
    }
public  String getByte( String arrayValue, int index)
    throws IllegalArgumentException, ArrayIndexOutOfBoundsException
{
return arrayValue;
    }

String x = arrayValue;
switch (x) {
  case 0:
    push();
    S = StartingPoint;
    System.out.println("S");
    break;
  case 1:
    Move();
    System.out.println("Help, I am trapped");
    break;
  case E:
    Exit();
    System.out.println("I am free");
    break;

  default:
    doSomethingElse();
}

}

public interface Stack
{
void push(Object X);
void pop();
Object top();
Object move();
boolean isEmpty();
public void push(Object X)
{
 if( topofStack + 1 == theArray.length)
     fillArray();
   maze[++topOfStack ] = x;
}

public void pop()
    {
     if(isEmpty())
         throw new UnderflowException( "ArrayStack pop");
     topOfStack--;
    }

public Object top()
{
    if( isEmpty())
        throw new UnderflowException( "ArrayStack top");
    return theArray[topOfStack];

}

}

Feel free to ask any follow up Questions

Add a comment
Answer #2

To implement the maze-solving algorithm using a single linked list, you can follow these general steps:

  1. Read the maze data from the input file and store it in a suitable data structure, such as a 2D array.

  2. Print the maze with numbered rows and columns to display it to the user.

  3. Prompt the user to enter the starting point (row and column) in the maze.

  4. Create a single linked list to store the path taken through the maze.

  5. Implement a recursive function or a loop that explores the maze, following the rules provided. The function should track the current position, check for possible moves, update the linked list with each step, and continue until reaching the exit or getting trapped.

  6. If a path to the exit is found, print the maze with the path marked using plus signs (+), or print the linked list representing the path.

  7. If no path to the exit is found, print a message indicating that the person is trapped.

Please note that the actual implementation details, such as defining the linked list structure, writing the maze exploration algorithm, and handling specific movements, will depend on your programming language of choice.

I recommend starting by writing the code to read the maze data, display the maze, and prompt the user for the starting point. Then, you can proceed with implementing the maze exploration logic using a single linked list. If you encounter any specific issues or have further questions, feel free to ask for assistance.


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you......
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and...

    PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and mark a path out of the maze, which is represented by a 20x20 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically or horizontally in any direction that contains a 0; you may not move into a square with a 1. If you move into the square with...

  • Need help with java In this program you will use a Stack to implement backtracking to solve Sudok...

    need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class.  Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop()  Test your class thoroughly before using it within the soduku program Part II. Create...

  • When outputting the path found in the proposed program, the direction of movement is output. Howe...

    When outputting the path found in the proposed program, the direction of movement is output. However, the direction of movement to the last movement, EXIT, is not output. To print this out, please describe how to modify the proposed program. #include <stdio.h> #define NUM_ROWS 5 #define NUM_COLS 3 #define BOUNDARY_COLS 5 #define MAX_STACK_SIZE 100 #define FALSE 0 #define TRUE 1 ​ ​ ​ typedef struct { short int row; short int col; short int dir; } element; ​ element stack[MAX_STACK_SIZE];...

  • For this homework you will be making a maze solver. Your program will take in from...

    For this homework you will be making a maze solver. Your program will take in from a file 2 things. The size of the square maze, and the maze itself. The maze will consists of numbers between 0 and 3, where 0 is the start of the maze, 1 is an open path, 3 is a wall, and 2 is the end of the maze. For example a 6x6 maze could be represented by the following file, there will be...

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

  • Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL: Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem3. CODE PROVIDED FOR PROBLEM 2: import java.util.Scanner; public class Problem2 { public static void main( String [] args ) { //N...

  • C++ really need help I will rate you well promise Write a program that will use...

    C++ really need help I will rate you well promise Write a program that will use a linked list to hold the following information: Date (int), Time (int), TZ (string), Size (Int) and Name (string) Follow the guidelines below: Records should be read from a file by the main program. And content should be stored in the doubly linked list or single linked list. After that, you can print separately dates or times or names ... or print hole line  ...

  • URGENT!!!!! I need to develop a C++ program that uses a recursive function to solve this...

    URGENT!!!!! I need to develop a C++ program that uses a recursive function to solve this maze problem: (No classes please!!!!) A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int n;       ...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end show the exact Output that's shown in the Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT