Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Whats wrong with my code?

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Whats wrong with my code?

    public class Robot {
    public Robot(double x, double y) {
    	x = 0.0;
    	y = 0.0;
    }
     
      public double getX() {
        return X;
      }
     
      public double getY() {
        return Y;
      }
     
      public double getHeading() {
    	  int h = 0;
    	if (h >= 0 && h < 360)
    		return h;
    	return h;
      }
     
      public double getBatteryCapacity() {
        if (BCW <= 1.0)
    	return 1.0 - BCW;
        else
    	return 1.0;
      }
     
      public double readBatteryMeter() {
        return readBatteryMeter(); 
      }
     
      public double distance() {
    	  if (distanceTravelled <= 0)
    		  return 0; 
    	return distanceTravelled;
      }
     
      public void turnRight() {
    	  if (MPW + X == distanceTravelled*turnRight)
    		    return;
      }
     
      public void turnLeft() {
    	  if (MPW + X == distanceTravelled*turnLeft)
    		    return;
      }
     
      public void recharge(double seconds) {
        wattsAvailable += SPW*MPW;
      }
     
      public double goForward(double distance) {
    	  if (MPW + X == distanceTravelled*goForward)
        return distanceTravelled*goForward; 
    	  else
    	return 0;
      }
     
      private double wattsAvailable;
      private double X;
      private double Y;
      private double distanceTravelled;
      private double goForward;
      private double turnLeft;
      private double turnRight;
      private static final double MPW = 10.0;
      private static final double SPW = 2.0;
      private static final double BCW = 1.0;
    }

    I need an opinion on this code cause I just made it and I want it to work with another code.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Whats wrong with my code?

    Only read a tiny bit, You need to give more detail as to what the error is that you're getting.

    A quick thing i noticed that I'm assuming that you need is

    public Robot(double x, double y) {
    	x = 0.0;
    	y = 0.0;
    }

    Im assuming you require

    public Robot(double x, double y) {
    	this.x = x;
    	this.y = y;
    	x = 0.0;
    	y = 0.0;
    }

    As for the rest of your code, i can't comment.

    Btw, keep all your variable names lower case unless you declare variables as final.(even then I'm not totally sure though )
    Last edited by newbie; November 26th, 2010 at 07:18 PM. Reason: Added info

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Whats wrong with my code?

    hi , iam not that good at java , but i noticed things , i dont know but i think u cant use return with a void method , and about the first method u wrote "public ROBOT .." i think u shoud put somethin like void or double or int , or what ever , and like i said iam not good at java yet , ^_^

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Whats wrong with my code?

    public Robot was fine as it's his constructor.
    As long as there aren't any statements after his returns, he won't be given any compile-time errors.
    Good try though

Similar Threads

  1. my menu doesnt work can u tell me whats wrong
    By claymore in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 8th, 2010, 04:16 AM
  2. i'm new to java. whats is wrong in this code?
    By igorek83 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 30th, 2009, 08:38 PM
  3. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  4. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  5. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM