Results 1 to 2 of 2
  1. #1
    taliGLM is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default I am so lost in my java class

    I am so lost in my java class, what is a constuctor? Here is my code, what is wrong with it?

    import becker.robots.*;

    // This robot will be able to keep track of how many
    // moves it's made, and then be able to print a message to
    // the user saying that.
    class MysteryRobot09 extends Robot
    {
    numberOfMovesMade;

    MysteryRobot09( City c, int st, int ave, Direction dir, int num)
    {
    super(c, st, ave, dir, num);
    }

    public void startCountingMoves()
    {
    this.numberOfMovesMade = 10();
    }

    public void moveCounted()
    {
    this.move();
    this.numberOfMovesMade = this.numberOfMovesMade * 2;
    }

    public void printNumberOfMoves()
    {
    System.out.println("Since I started counting, I moved:");
    System.out.println( this"numberOfMovesMade");
    System.out.println("times!");
    }
    }

    public class ICE_09_Errors extends Object
    {
    public static void main(String[] args)
    {
    City forgetsVille = new City();
    MysteryRobot mary = new MysteryRobot09(forgetsVille, 4, 1, Direction.EAST, 0);
    Wall aWall = new Wall(forgetsVille, 2, 5, Direction.NORTH);

    // First keep track of these 4
    mary.startCountingMoves();
    mary.moveCounted();
    mary.moveCounted();
    mary.moveCounted();
    mary.moveCounted();
    mary.printNumberOfMoves();

    mary.turnLeft();

    mary.startCountingMoves();
    while(mary.frontIsClear());
    {
    mary.moveCounted();
    }
    mary printNumberOfMoves();
    }

    ;)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    what is a constuctor?
    Special method with no return type and same name as enclosing class.
    See Providing Constructors for Your Classes for more.
    Java Code:
    // Type must match:
    // declaration type   ==   constructor type
    MysteryRobot09      mary = new MysteryRobot09(forgetsVille, 4, 1,
                                                     Direction.EAST, 0);
    
        MysteryRobot09( City c, int st, int ave, Direction dir, int num)
        {
            // This sends these arguments to the superclass Robot
            // which will keep them.
            super(c, st, ave, dir, num);
        }

Similar Threads

  1. need help with program im lost
    By lifeturn in forum JCreator
    Replies: 1
    Last Post: 10-28-2008, 07:09 PM
  2. Lost my javadocs
    By orchid in forum Eclipse
    Replies: 3
    Last Post: 04-30-2008, 09:45 PM
  3. A little lost with for loops and making a design
    By LinxuS in forum New To Java
    Replies: 5
    Last Post: 01-22-2008, 09:05 AM
  4. Absolutely Lost
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 06:25 PM
  5. Help Needed - I'm so lost
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 01:54 AM

Posting Permissions

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