I am a beginner in Java programming and I want you to provide me a code of the following steps:


First: create 2-D environment

0 0 0 1 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 1 0 0 0
1 0 0 1 0 0 0 0 1 1
0 1 2 0 0 0 0 0 0 0
0 0 1 0 0 1 0 0 0 0
0 1 0 1 0 1 0 1 0 1
1 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 1 0 0 1
0 0 0 1 0 0 3 0 1 0

Where
0 is the path
1 is a wall
2 is the robot
3 is the target

Find the shortest path from 2 to 3 using shortest path algorithm.


Second: create 2-D array of the type (int ) contains only 0 value.

third: Create 2-D array of the type (char) [same as2-D array of the type (int )] Where


N instead of 0
Z instead of 1
T instead of 3

any help!!!

Recommended Answers

All 3 Replies

I started by this code for the environment ,but every time they ask me extra things which I can not do as a beginner
realy they confuse me
I want your help regarding the steps ..

import java.awt.*;         
import java.awt.event.*;	
import javax.swing.*;	
	

class Ckku extends JFrame 
{
  Container yourContainer; 
  JPanel eastPanel = new JPanel();
  JPanel menuArea = new JPanel();  
  JPanel mazeArea = new JPanel();
  JPanel compassArea = new JPanel();
  JTextField helloTextField;    
  
  int [][] imazePlan = {
		  				{0,0,0,1,0,0,1,1,0,0},
		  				{0,0,0,0,0,0,0,0,0,0},
		  				{1,1,0,0,0,0,1,0,0,0},
		  				{1,0,0,1,0,0,0,0,1,1},
		  				{0,1,2,0,0,0,0,0,0,0},
		  				{0,0,1,0,0,1,0,0,0,0},
		  				{0,1,0,1,0,1,0,1,0,1},
		  				{1,1,0,0,0,0,0,1,0,0},
		  				{0,0,0,1,0,0,1,0,0,1},
		  				{0,0,0,1,0,0,3,0,1,0},
		  				
          			  };
  mazeLayout mlayout = new mazeLayout();
  JPanel [][]wall = new JPanel[imazePlan.length][imazePlan[0].length];

  int xPosition=2;
  int yPosition=2;
  int xMovement=0;
  int yMovement=-1;
  int rotation=0;
  
  public Ckku()
  {
    super ("Ckku Computer science");     
    yourContainer = getContentPane();
    yourContainer.setLayout(new BorderLayout());
    
    eastPanel.setLayout(new BorderLayout());
    yourContainer.add(eastPanel, BorderLayout.EAST);
    
    controlSetup();
    setExtendedState(MAXIMIZED_BOTH);
    setVisible(true);
  }

  public class mazeLayout extends JPanel {
	  mazeLayout(){
    	 setLayout(new GridLayout(imazePlan.length, imazePlan[0].length)); 
         JPanel [][]wall = new JPanel[imazePlan.length][imazePlan[0].length];
            for(int i=0; i<imazePlan.length; i++){ 
            for(int j=0; j<imazePlan[0].length;j++){ 
               wall[i][j] = new JPanel();
               if(imazePlan[i][j]==0) 
               wall[i][j].setBackground(Color.WHITE);
               else if(imazePlan[i][j]==2) 
	           wall[i][j].setBackground(Color.BLUE);
               else if(imazePlan[i][j]==3) 
		       wall[i][j].setBackground(Color.RED);
               else if (imazePlan[i][j]==1)
               wall[i][j].setBackground(Color.BLACK);
               add(wall[i][j]);
            }
         }
      }
  }
  
public void controlSetup()  
  {

	    menuArea.setLayout(new GridLayout(0,2));  
	    mazeArea.add(mlayout);
	   eastPanel.add(compassArea, BorderLayout.CENTER);
       eastPanel.add(mazeArea, BorderLayout.NORTH);
	   eastPanel.add(menuArea, BorderLayout.SOUTH);
  }
  
  public static void main(String[] args)
  {
        try
        {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e)
        {
            System.err.println("error " + e);
        }
        Ckku Ckku1 = new Ckku(); 
        Ckku1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  }
}

FYI, there was recently a thread in this forum in which I explained how to create a shortest path algorithm. If you do a search for 'maze' it should be one of the first results. In short, use a queue to find the shortest path of the maze.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.