Program won't move my bot properly
New to Java programming and need help with the following code. Compiles with no problems but bot will not most past line 17 when program runs. Please be patient with me, I'm new...:=(:
Code:
1 import becker.robots.*;
2 /**
3 is a robot designed to pick up trash cans in a neighborhood.
4 */
5 public class ACMETrashTruck extends RobotGB implements SanitationEngineer
6 {
7
8 /**creates a ACMETrashTruck using only the caller provided values.
9 */
10 public ACMETrashTruck(CityGB city, int street, int avenue, Direction direction)
11 {
12 super(city,street,avenue,direction);
13 }
14
15 //robot collects neighborhood trash
16 public void collectNeighborhood()
17 { this.moveForward(); //this is the only thing he does. The bot stops moving, it’s like he doesn’t understand what collectEastbound means. I know this only because after line 17 I added a turnRight command and he did it but nothing else beyond that.)
18 while(this.canSeeThing())
19 {
20 this.collectEastbound();
21 this.moveForward();
22 this.collectWestbound();
23 }
24 }
25 //method of collecting eastbound trash
26 public void collectEastbound()
27 {
28 while(this.canSeeThing());
29 {
30 this.pickupThing();
31 this.moveForward();
32 }
33 this.turnRight();
34 this.moveForward();
35 this.turnRight();
36 }
37 //method of collecting westbound trash
38 public void collectWestbound()
39 {
40 while(this.canSeeThing());
41 {
42 this.pickupThing();
43 this.moveForward();
44 }
45 this.turnLeft();
46 this.moveForward();
47 this.turnLeft();
48 }
49 // Add methods as required. Be sure to prefix them with description of what they do. See line 7-9 as an example.
50 // Hint: Compile this file and see what the compiler tells you is missing.
51 }
Re: Need Help with Intro to Programming Class
First off, please don't waste time complaining about your instructor. Many people here learned Java without the aid of an instructor, fellow students, or any of the other perks you get from actually enrolling in a class. Plus 75% of people who come here are going to move on instead of reading the wall of text.
Secondly, please use the code tags when posting code. Unformatted code is pretty much impossible to read.
Finally, did you try to compile this? What happens?
Re: Need Help with Intro to Programming Class
Re: Need Help with Intro to Programming Class
Maybe this doesn't see anything at line #18; add a couple of System.out.println( ... ) statements at 'important' points (such as System.out.println(this.canSeeThing()) before that while loop) and see what happens. Also, that semi colon in line #28 doesn't belong there; maybe there are more similar mistakes in your code, I didn't check.
kind regards,
Jos
Re: Need Help with Intro to Programming Class
Thank you Jos, it was the semicolons. Your patience and kindness is much appreciated.
Re: Need Help with Intro to Programming Class
Quote:
Originally Posted by
DarrylBurke
Thank you for the links. I think I've got it now. Noobs can be so annoying-I know.