create a program do the ff:

A room w/ 20 by 20 array of tiles.

Inside the room is a mechanical turtle w/ a pen. The turtle accepts input in the ff. method:

1 = pen up
2 = pen down
3 = turn right
4 = turn left
5,no = move forward(where no is the number of tiles to that the turtle will pass
6 = print the content of the array
9 = terminate the program

Initially the turtle is at 0,0, facing south with its pen down. As the turtle moves around the room with its pen down, the floor is marked an *.

The ff input will produce an output like this:

INPUT OUTPUT
4 * *
5,3 * *
2 * *
3 * *
5,5 ***
4
5,3
4
5,5
6
9

I guess you missed this at the top of the main forum page?

don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.

I guess you missed this at the top of the main forum page?

please share me a link.. thanks

I guess you didn't read my previous post?

I guess you didn't read my previous post?

help me please

Well, I see by this line:

As the turtle moves around the room with its pen down, the floor is marked an *.

that you're to do this in the console rather than graphically. This will save you a lot of math, since you won't have to calculate angles and distances. So you've just got to design a moderately complicated machine with a few moving parts. It's not an easy problem, but if you're in a class where you've been given this assignment there's at least one person who thinks that you are or should be able to solve it. Why not believe it, and see where that gets you?

So, you have to start somewhere. What sorts of classes do you think you might need for this? I would guess that you could do this one with a single-class, imperative-type program, but there might be some advantages to doing it more object-y. (I don't know for sure either way, since I've never written this program) Why don't you try to sketch out a design that you like - not a program, a design - and see where you get with that?

Well, I see by this line:

that you're to do this in the console rather than graphically. This will save you a lot of math, since you won't have to calculate angles and distances. So you've just got to design a moderately complicated machine with a few moving parts. It's not an easy problem, but if you're in a class where you've been given this assignment there's at least one person who thinks that you are or should be able to solve it. Why not believe it, and see where that gets you?

So, you have to start somewhere. What sorts of classes do you think you might need for this? I would guess that you could do this one with a single-class, imperative-type program, but there might be some advantages to doing it more object-y. (I don't know for sure either way, since I've never written this program) Why don't you try to sketch out a design that you like - not a program, a design - and see where you get with that?

share me a lick please.. so i can do it.

Don't whine. Do.

>>share me a lick please.. so i can do it.

Good thing that you wrote this post, because I'm going to refer to it anytime you do a request that involves doing it for you. So now, if you could provide us with some evidence that shows your effort, you've got a great chance of getting help. However if you don't, and continue ignoring replies, then other people at this forum will interpret it as follows: 1) You don't want to do any effort. 2) You don't want to be helped.

>>share me a lick please.. so i can do it.

Good thing that you wrote this post, because I'm going to refer to it anytime you do a request that involves doing it for you. So now, if you could provide us with some evidence that shows your effort, you've got a great chance of getting help. However if you don't, and continue ignoring replies, then other people at this forum will interpret it as follows: 1) You don't want to do any effort. 2) You don't want to be helped.

please help me sir.. please..

commented: Stop whining. You know the conditions! -2

please help me sir.. please..

You're starting to sound like Princess Leia.

What is it that you want help with?

Then write a 2D array of size 20x20. Have variables to save the position of the turtle and its current direction. When the user enters an input, use if statements to determine the position that it needs to move. If it is a valid position within the limits of the array then change the values of the variables that store the position and the direction.

After each move print the array and display a special character at the position of the turtle

// TurtleGraphics.java

import java.awt.Color;
import java.*;
import javax.swing.JPanel;
import java.util.Scanner;


public class TurtleGraphics
{


int xpos=0, ypos=0; //turtle always starts at 0,0 position
final static int penUp = 1;
final static int penDown = 2;
final static int turnRight = 3;
final static int turnLeft = 4;
final static int moveFwd = 5;
//final static int moveFwd2 =12;
final static int print = 6;
final static int end = 9;


int commandArray [] =

{
penDown,
moveFwd,
12,
turnRight,
moveFwd,
12,
turnRight,
moveFwd,
12,
turnRight,
moveFwd,
12,
penUp,
turnRight,
moveFwd,
6,
penDown,
turnRight,
moveFwd,
11,
print,
end
};

boolean penPosition;
boolean pen_down = true;
boolean pen_up = true;



// enters the commands for the turtle graphics
public void enterCommands()
{
Scanner input = new Scanner( System.in );

int MAXCOMMANDS [];
int count[];
int commandNumber;
int command[];

int inputCommand []= new int [6]; //array of inputCommand
//int inputCommand[] = {2,5,12,3,5,12,3,5,12,3,5,12,1,6,9};

//Enter command (9 ) to end input;

System.out.printf(" 1. Pen Up\n"); //prints out header of the exercise
System.out.printf(" 2. Pen down\n"); //prints out header of the exercise
System.out.printf(" 3. Turn right\n"); //prints out header of the exercise
System.out.printf(" 4. Turn left\n"); //prints out header of the exercise
System.out.printf(" 5. Move forward\n"); //prints out header of the exercise
System.out.printf(" 6. Print\n"); //prints out header of the exercise
System.out.printf(" 9. End\n"); //prints out header of the exercise
// System.out.print("Please enter a command: "); //prompt to enter first number

while ( inputCommand != 9 && count < MAXCOMMANDS )
{

commandArray[ count ][ 0 ] = inputCommand;

// prompt for forward spaces

count++;

System.out.print( "Enter command (9 to end input): " );
inputCommand = input.nextInt();
} // end while

executeCommands();
} // end method enterCommands


// executes the commands in the command array
public void executeCommands()
{

command = commandArray[ commandNumber ][ 0 ];

// continue executing commands until either reach the end
// or reach the max commands

while ( commandNumber < count )
{
//System.out.println("Executing...");
// determine what command was entered
// and perform desired action
boolean penUp;
boolean penDown;
boolean turnRight;
boolean turnLeft;
boolean moveFwd;
//boolean moveFwd2;
boolean print;
boolean end;

switch ( command )
{

case 1: // pen up
penUp = false;
break;

case 2: // pen down
penDown = false;
break;

case 3: // turn right
turnRight = false;
break;

case 4: // turn left
turnLeft = false;
break;

case 5: // move forward 12 spaces
moveFwd = false;
//moveFwd2 = false;
break;

case 6: // display 20x20 array
print = false;
break;

case 7: // end
end = false;
break;


} // end switch

command = commandArray[ ++commandNumber ][ 0 ];
} // end while
} // end method executeCommands

// method to turn turtle to the right

//	public void getturnRight() // need to know how to move 45 degrees.
//	 {
//	 return turnRight;
//	 }



// method to turn turtle to the left

// public void getturnLeft() // need to know how to move 45 degrees.
// {
// return turnLeft;
// }


// method to move the pen
public boolean getPenPosition()//check to see if pen is up
{
return penPosition;
}


public boolean pickPenUp()
{
penPosition = pen_up;
}

//public boolean getPenPosition() //check to see if pen is down
//	{
//	 return penPosition;
//	}


public boolean putPenDown()
{
penPosition = pen_down;
}

// method to print array drawing
} // end class TurtleGraphics
commented: You are a fool. -2
commented: Post help, not code. +0

yeah, now he's really going to put effort in it ..

@PeterRossy, you think you just helped him? No, you just push him in one of the assignment so he can go and play games or chat with friends about rubbish on facebook and come back with another assignment.

We have nice announcement that says We only give homework help to those who show effort

Peter - does it really count as help in this case? :)

I don't think this will even compile - I don't have time to check it now, but I'm looking at commandArray, declared as an int array and referenced as a 2D int array.

There's some other suspicious bits as well - the declaration of MAXCOMMAND as an array (and the conspicuous failure to use it - couldn't figure out why it wasn't working, I bet) for one.

But the real kicker was the fairly important methods at the end, helpfully commented out!

HERE IS ALL MOANING BY kennski23 that I accidentally merged with jon.kiparsky post. Sorry John.

Please help me with this using BufferedReader.. please.. do i have to use for and if else if?

please help.. how can i do it w/out color.. i have to use bufferedreader.. please help me..

and im using 2D array.

please sorry im dumb.. :((

As the turtle moves around the room with its pen down, the floor is marked an *.

@kennski23 start providing some input or I will advice people to stop helping you. You are not dumb you are lazy

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.