I'm trying to finish this code..I'm still getting errors..can some plese help me!

[TEX]

import java.util.Scanner;
import java.util.Random;

public class robot
{
	public static void main (String args [])
	{ 
	int robot_x = 0;
	int robot_y = 0;
	int robot_m_x = 0;
	int robot_m_y = 0;
	
	int[] robot_instructions = new int[64];
	int i = 0;
       int robot_state = 0; 
	robot_instructions[0] = 1;
	maze[4][5] = 2;
	maze[6][7] = 3;
	maze[1][1] = 1;
	maze[8][8] = 4;
	maze[3][2] = 3;
	maze[4][1] = 2;
	robot_x = 1;
	robot_y = 1;

	robot_state = 1;
       Random rand = new Random();
       for(int i = 0; i < 64; i++)
       {
          int robot_instructions[i] = rand.nextInt(4);
	
	   switch(robot_instructions[i])
	   {
	       case 1:robot_x = robot_m_x;
	       robot_y = robot_m_y + 1; //move 
	       break;
	       case 2:robot_x = robot_m_x;
	       robot_y =  robot_m_y + 2 ; //jump 
	       break;
	       case 3:       
	       robot_x = robot_m_x - 1; //Left
	       break;
	       case 4:
              robot_x = robot_m_x + 1; //Right
              break;
	   }
       }

       System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
	System.out.println ("Robot State: ");
       if ( ((robot_x == 4) && (robot_y == 5)) || ((robot_x == 4) && (robot_y == 1)))
       {
          System.out.println("Robot has fallen into a chasm");
       else if((robot_x == 6) && (robot_y == 7)) || ((robot_x == 3) && (robot_y == 2));
	{
	   System.out.println("Robot has fallen into a trap");
       else if((robot_x == 8) && (robot_y == 8));
       {
	   System.out.println("Robot has reached Destination");
       else
	{
          System.out.println("Robot is at a safe place");

       switch(robot_state[i])
	{
	case 1:robot_state = 1; //safe
	System.out.println ( "Robot is at a safe place");
	break;
	case 2:robot_state = 2; //chasm
	System.out.println ("Robot falls into Chasm");
	break;
	case 3:robot_state = 3; //trap
	System.out.println("Robot falls into the trap");
	break;
	case 4:robot_state = 4; //destination
	System.out.println( "Robot reaches Destination");
	break;
	case 5:robot_state = 5; //Failed
	System.out.println ( "Robot fails to reach Destination");
	break;
 	} 
   }
}

Use indentation and line up your parenthesis. I think you'll see your problem(s) then!

What maze? You have a meandering robot only meandering in one general direction!


You start your robot on 0,0 but you don't prevent it from going negative! If it's at x = 0, you let it go -1 and beyod.

The robot never goes -y.


Look where the for loop 64 close brace is! And it isn't at the bottom of the code!

I'm not even sure how this compiles as you have else if's inside an if statement! Where's the close brace?
Same for the switch case, its an else condition, not in the main flow!

And other problems too! But start there, reformat, indent properly, line up your braces, and repost!

This article has been dead for over six months. Start a new discussion instead.