-1

i am using the import becker.robots file for this assignment!

I must create a class DistributeBot (extended RobotSE) which will put down a number of 'things' in the shape of 2 squares.

When the main method is then created, a single call to a method (which i must create myself using stepwise refinement and also contains a parameter) called this.putThings();

The method i am to create should have a single variable parameter to define the size of the squares! ie a parameter of (4) will make a 4x4 square of 'Things'.

The robot should set out the Things one line at a time from left to right! (once one line is displayed, it should move back to the LHS before displaying the next line)

I think i will be able to complete the scenario without problem whenever i am certain on how to create the method with the parameter i have specified.

Assumptions. 1. Starting position of the robot will always be the same. ie starting at 1, 1. 2. There will always be enough 'things' in the robots backpack to display the two squares.

Anyone have an idea how I would go about setting up this method initially with the variable parameter?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user3223921
  • 1
  • 1
  • 5
  • Do **you** have any idea how **you** would approach your assignment? – Josh M Jan 22 '14 at 20:04
  • First of all i obviously must create a new robot class and create a new constructor! within the same class file i intend to use stepwise refinement to come to the conclusion i have stated above and once i figure out how to create the parameter on the method i should be flying again! ie as far as ive got with creating the method is `public void putThings(int squareSize)` but i am unsure what to do after this and how to get define what the parameter must do?! – user3223921 Jan 22 '14 at 20:15
  • You decide what to do with the parameter `squareSize`. – Josh M Jan 22 '14 at 20:18
  • I am honestly not entirely sure how i even go about starting off the expression under the `public void putThings` etc. Would you be willing to offer any greater help, not asking for the exact code that i need, just an aide to get to finding the answer!? – user3223921 Jan 22 '14 at 20:33

1 Answers1

0

If you have your method starting

Public void MakeSquare(int size)
{
    for(int i = 0; i < size; i++) 
    {
        for(int x = 0; x < size; x++)
        {
            //drop thing
            //move right
        }
        for(int y = 0; y < size; y++)
        {
            //move left
        }
        //move up
    }        
}

Whilst reading the question you should try and break it down into its simplest parts.

start with Build a square that is the most abstract form of the scenario and so makes your method, then break it down

//I want to move up until I hit size limit
for each number in "the size you want" 
    //I want to move right and drop a thing, until I hit size limit
    for each number in "the size you want"
        drop a thing
        move one right
    endloop
    //I want to move back to the LHS until I hit size limit
    for each number in "the size you want"
        move one left
    endloop
    //then make the move up
    move up
endlood

If you make this method and call it twice you will make the 2 squares as required)

Melbz
  • 512
  • 4
  • 14
  • Thanks very much for this! really appreciated, however how will this work when i change the variable parameter ie if i want a square sized 4x4 i type in '4', will it still work if i type in '5', will it give me a 5x5 square!? What i dont understand is how i make the parameter logic. Im still unsure as to what you mean! But thanks for the help thus far!? – user3223921 Jan 24 '14 at 18:17
  • I left the logic alongside the code (not tested) so you can see my thought process, hopefully you will be able to see how it translates – Melbz Jan 28 '14 at 10:11
  • Basically when ever you see repeated data in code, try and put it into a variable (like using 'size' here) then you only need to set it once (when you pass it in). You can call this method as many times as you want in the main method with any value. – Melbz Jan 28 '14 at 10:17