Results 1 to 2 of 2
Thread: I am so lost in my java class
- 04-30-2008, 09:43 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
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();
}
;)
- 04-30-2008, 10:02 PM #2
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
-
need help with program im lost
By lifeturn in forum JCreatorReplies: 1Last Post: 10-28-2008, 07:09 PM -
Lost my javadocs
By orchid in forum EclipseReplies: 3Last Post: 04-30-2008, 09:45 PM -
A little lost with for loops and making a design
By LinxuS in forum New To JavaReplies: 5Last Post: 01-22-2008, 09:05 AM -
Absolutely Lost
By Lehane_9 in forum New To JavaReplies: 2Last Post: 12-03-2007, 06:25 PM -
Help Needed - I'm so lost
By adlb1300 in forum New To JavaReplies: 3Last Post: 11-14-2007, 01:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks