0 Replies - 154 Views - Last Post: 23 January 2014 - 06:50 AM Rate Topic: -----

#1 MichaelEdward  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-January 14

Need help with java robots

Posted 23 January 2014 - 06:50 AM

I'm stuck with a bit of code in which I have to use becker.robots to create two squares using 'things'.
the number of 'things' depends on what the user has typed in. For instance in this case I am trying to make 4x4 squares. so the user types in 4.
once the robot has planted one line it must return to the first 'thing' move to the line and plant another four. It must always plant from left to right.
This is the code I have so far, it plants one line, stops, turns but doesnt go back.


import becker.robots.*;

public class DistributeBot extends RobotSE
{
	//constructor
	public DistributeBot(City aCity, int aStreet, int anAvenue, Direction aDirection, int numThings)
	{
		super(aCity, aStreet, anAvenue, aDirection, numThings);
	}

	//Methods must include one called putThings which has a parameter to define the size of the squares.

	public void putThings (int length)
	{
		this.plantsquare(length);
	}



		protected void plantsquare(int length)
		{
			length = length -0;
			this.move();
			this.turnLeft();

			this.plantLine(length);
			this.movebacktostart();



		}

	protected void plantLine(int len)
	{
		while (len > 0)

		{
			this.plantIntersection();
			this.move();
			len=len-1;
		}
	}


protected void plantIntersection()
{
	this.putThing();
}

	public boolean moveToCertainAvenue(int anAvenue)

	{
		return this.getAvenue() == anAvenue;
	}

	public void movebacktostart()
	{
		this.turnRight();
		this.move();
		this.turnRight();

		while(!this.moveToCertainAvenue(1));
		{
			this.move();

		}

	}
}

Thanks M

This post has been edited by macosxnerd101: 23 January 2014 - 07:09 AM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Page 1 of 1