CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2009
    Posts
    15

    Help With Sweeper Robot Assignment

    Hey I have an assignment for Java due in a few days and am having a lot of trouble figuring out where to start. I think once I get going I will have more luck, but at this point, I need some help. I am attaching the homework to this thread, but also will paste the important parts below.

    If anyone can guide me at all, thank you very much!

    =================Assignment========================
    Write a Java program to implement a new data type called a SweeperRobot. When a SweeperRobot is initialized, it is placed on one of the cells (its position) on a long tile floor (its habitat), whose length is specified by the length of a given array of integers. The integers in the array represent the number of items the robot must remove before leaving each cell. Initially the robot is placed on the floor to face either to the left or to the right (its orientation). A SweeperRobot is capable of detecting when it reaches an obstacle (wall). For example, if a robot is facing left and has picked up all items in cell 0 and instructed to move it will hit a wall, it can change direction in order to visit the other cells. At any time, as the robot moves it will keep track of its position on the tile floor.


    Part 1: Implementing the SweeperRobot. In this part of the assignment, YOU ARE THE CREATOR of the SweeperRobot class! Your first job is to decide on the components of a SweeperRobot. You will need an integer array to specify the length of the floor and the number of items in each cell. You will need a variable to hold the starting position that the robot finds itself at on the floor. Finally, you will need to indicate whether the robot is facing to the left or to the right (a boolean). For example, the robot shown above is placed at position 3 of a tile floor of length 6. The robot is facing right, and the array representing the items on each cell is

 int[] items = {2,1,4,0,3,2};

Design a constructor that allocates memory for a SweeperRobot and initializes each of these components.
    A SweeperRobot has the ability to determine whether or not it is blocked by an obstacle.
    public boolean isBlocked()
    In addition, a SweeperRobot can tell whether or not all items have been removed from the tile floor.
    public boolean isFloorClean()
    A SweeperRobot responds to a move() message of the form

 public void move()
    If the cell on which the robot is standing has no item to pick up the robot will move to the next cell provided it is not blocked, otherwise, it will change direction only.
    If the cell on which the robot is standing has two or more items to pick up the robot will pick it up.
    If the cell on which the robot is standing has only one item to pick up the robot will pick it up and move to the next cell provided it is not blocked, otherwise, it will pick it up and change direction.
    A SweeperRobot is displayable. For example, the starting configuration of the robot shown above is
 |2|1|4|0|3|2|
 >
A SweeperRobot can be directed to clean the house (pick up all items on the floor). This method must display the robot after each move to see if your move() method is implemented properlyand it returns the total number of moves needed to clean the house.

 public int cleanHouse()
    Attached Files Attached Files

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help With Sweeper Robot Assignment

    My advice is to start by forgetting the computer for a while, and figuring out exactly what the task involves and how you would do it manually, first as the robot, then taking the computer's role.

    Use pen/pencil and paper to draw a grid of the area with items in the cells, and then step through the instructions as the robot until you fully understand what it needs to do. Then repeat the exercise as the computer, writing down the variables you'll need to hold information and control the robot, and getting an idea of where any decision points are and where loops might be involved. Don't think about any particular programming language at this point, just walk through the thing in English.

    When you fully understand all the bits of information you need to keep track of, and how they change as you step through the task, start thinking about the objects that will be involved, the responsibilities they each have, and which bits of data will be stored in which object. For example, the grid will have the walls and cells which are permanent, and the cells will hold varying numbers of items. The robot needs to know where it is on the grid, which way it's facing, how to find out what is on each side of it, and how to decide where to move next, etc. You may need a controlling object to set everything up and start things going and to decide when it's finished, and so-on.

    When you have worked out what all the objects are, what their responsibilities are, what their data is and how they will function and interact with each-other (remember each has a single, well-defined job to do), try a couple of trivial dry runs on paper, to see if it all hangs together and the objects work together to achieve the result.

    Only once you fully understand all aspects of the task, you have worked out a detailed design, and you know it works because you have stepped through a couple of examples by hand, should you go anywhere near the computer. The worst thing you can do is sit at the keyboard too early. It's hard enough writing legal Java syntax, without having to design your whole application on-the-fly at the same time.

    The bulk of development work and time is thrashing out a good design and making sure there are no surprises and that all the difficult bits are sorted out before any coding begins. Writing the Java code should just be a translation into Java of the detailed design you have on paper. The major objects generally become classes, the minor objects may be classes or variables - try to work them out before writing any Java code.

    If I had eight hours to chop down a tree, I would spend 6 hours sharpening an axe...
    Anonymous
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jan 2009
    Posts
    15

    Re: Help With Sweeper Robot Assignment

    Thanks very very much for that suggestion. I probably should have done that earlier because it made everything much easier when I went to code.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help With Sweeper Robot Assignment

    I don't understand why it isn't the first thing taught in programming courses - it's just as important as learning the language and it would save so much misunderstanding and frustration.

    The sooner you start to code, the longer the program will take...
    R. Carlson
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Feb 2009
    Posts
    3

    Re: Help With Sweeper Robot Assignment

    Is this for Georgy Novacky's Cs 401 programming class? I remember having an eerily similar project my freshman year and remember having troubles with it. I hope all went well with the program and if you would need any further help with it I'd be glad to lend a hend

  6. #6
    Join Date
    Jan 2009
    Posts
    15

    Re: Help With Sweeper Robot Assignment

    Yes this is for George Novacky's programming class hahaha

  7. #7
    Join Date
    Feb 2009
    Posts
    3

    Re: Help With Sweeper Robot Assignment

    If you need any more help ill be glad to take a look at your code of what you have so far or at your .class file if you want to send it to me at ncarm11@yahoo.com I'm pretty sure I still have that code laying around somewhere

  8. #8
    Join Date
    Jan 2009
    Posts
    15

    Re: Help With Sweeper Robot Assignment

    That'd be amazing.

    Do you have gtalk? mine is lbrapidSPLATgmail.com if you wanted to try chatting on there.


    Thanks!

  9. #9
    Join Date
    Feb 2009
    Posts
    3

    Re: Help With Sweeper Robot Assignment

    No no G talk sorry just email i posted above, I have work for two hours coming up but would be glad to help if you sent me a mail of your source or whatever you'd like with comments written in where you need help and i can send help back

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured