Results 1 to 7 of 7

Thread: Help with code?

  1. #1
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Help with code?

    Hello, I am very new with this and just started taking an AP Comp Sciences class, and a pre-test we have is this in dr. java:
    Create a grid with 5 rows and 5 cols.
    Create a bug object in the center of the grid that will do nothing.
    Create a second bug object that will travel around the first bug in a square.
    When the square is complete the non-moving bug removes itself from the grid and the moving Bug has a party.

    Here's my code:
    Java Code:
    public class Bug
    {
      public static void main(String[] args)
      {
        grid gr;
        gr= new Grid(5,5);
        bug b1;
        b1= new Bug(2,2,gr);
        bug b2;
        b2= new Bug(1,1,gr);
        b2.turn();
        b2.turn();
        b2.move();
        b2.move();
        b2.turn();
        b2.turn();
        b2.move();
        b2.move();
        b2.turn();
        b2.turn();
        b2.move();
        b2.move();
        b2.turn();
        b2.turn();
        b2.move();
        b2.move();
        b1.removeSelfFromGrid();
        b2.party();
      }
    }
    It says that there are four errors and that the grids and bugs cannot be resolved to a type, when i delete one of the semi colons, it says I only have one error and that I need to put a semi colon in, can anyone help?
    Last edited by quad64bit; 08-22-2012 at 10:09 PM. Reason: Added code tags for OP

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: Help with code?

    Please use the [CODE] bbcode tags when posting code to preserve the structure of the code.

    What previous experience do you have with Java? Are you completely new?
    What is a bug? You just create objects of the class Bug, but what is the class really? That code will never work on it's own.

  3. #3
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: Help with code?

    I am completely new, and I am not sure, this was just given as a test in a class with Dr. Java, and this is apparently the right code to use with it.

  4. #4
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: Help with code?

    We need the full material to be able to help you. As I told you, that code wont run on it's own.

    I assume that you in the test is given complete classes of Bug and Grid, and that your task is then to just use them in ways that the test says. If so, then maybe you are right, but once again, that code will never run without added classes and code.

  5. #5
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Help with code?

    Quote Originally Posted by darkmajik666777 View Post
    Hello, I am very new with this and just started taking an AP Comp Sciences class, and a pre-test we have is this in dr. java:
    Isn't the purpose of a pre-test to see what you know before studying the material?

    I have taken this course as well. You'll have fun!
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Help with code?

    I see one 'bug' on line 7.
    Java Code:
     bug b1;
    The 'b' in bug should be capital, because you are referring to a class type (which is always camel case!).

    I'm guessing it's the same problem with grid, which should be Grid.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Help with code?

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 02:40 AM
  2. Replies: 3
    Last Post: 08-10-2011, 09:17 AM
  3. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  4. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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