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 2 of 2

Thread: Robot help.

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

    Default Robot help.

    Hi!
    I'm new to this programming stuff and I'm currently struggling.
    I was given a project to construct a Robot with a fully charged battery and to make it move with certain buttons.

    I was given an incomplete code by my teacher, but I don't really understand what I'm doing.

    public class Robot {
     
      /**
       * Constructs a robot with a fully charged battery.
       * The initial heading is zero degrees (north).
       * @param x initial x coordinate, in meters.
       * @param y initial y coordinate, in meters.
       */
      public Robot(double x, double y) {
     
      }
     
      /**
       * Gets the x-coordinate of this robot.
       * @return the x-coordinate, in meters.
       */
      public double getX() {
        return 0.0; // TODO
      }
     
      /**
       * Gets the y-coordinate of this robot.
       * @return the y-coordinate, in meters.
       */
      public double getY() {
        return 0.0; // TODO
      }
     
      /**
       * Gets the heading of this robot. The heading is greater than or
       * equal to 0 degrees (north) and less than 360 degrees.
       * @return the heading, in degrees.
       */
      public double getHeading() {
        return 0.0; // TODO
      }
     
      /**
       * Gets the battery capacity for this robot.
       * @return the battery capacity, in watts.
       */
      public double getBatteryCapacity() {
        if (BCW <1.0)
    	return 0.5;
        else
    	return 0;
      }
     
      /**
       * Returns the current battery power for this robot.
       * @return current battery power, in watts.
       */
      public double readBatteryMeter() {
        return 0.0; // TODO
      }
     
      /**
       * Returns the distance between this robot's initial and current locations.
       * Because this robot may have turned, this distance may be less than the 
       * total number of meters traveled. For example, if the robot has returned
       * to it's initial location, this distance is zero.
       * @return the distance, in meters.
       */
      public double distance() {
        return 0.0; // TODO
      }
     
      /**
       * Turns this robot 90 degrees to the right (clockwise).
       * Power required to turn 90 degrees is the same as that required to go 
       * one meter. If insufficient power is available to complete the turn,
       * the robot consumes all remaining power but does not turn at all.
       */
      public void turnRight() {
        // TODO
      }
     
      /**
       * Turns this robot 90 degrees to the left (counter-clockwise).
       * Power required to turn 90 degrees is the same as that required to go 
       * one meter. If insufficient power is available to complete the turn,
       * the robot consumes all remaining power but does not turn at all.
       */
      public void turnLeft() {
        // TODO
      }
     
      /**
       * Recharges the battery for this robot for the specified amount of time.
       * Recharging has no effect after the battery's capacity is reached.
       * In other words, battery power must never exceed battery capacity.
       * @param seconds recharging time, in seconds.
       */
      public void recharge(double seconds) {
        wattsAvailable += BCW;
      }
     
      /**
       * Trys to make this robot go forward the specified distance. 
       * The robot goes only as far as possible with available battery power.
       * @param distance the distance to go, in meters.
       * @return the distance actually gone.
       */
      public double goForward(double distance) {
        return 0.0; // TODO
      }
     
      ///////////////////////////////////////////////////////////////////////////
      // Private fields declared here describe completely the state of this robot.
      // TODO: add private fields (neither static nor final).
     
      // Static fields are shared by all robots of this class of robots.
      // These fields are private, because they are accessed only by methods 
      // within this class. They are also final, because they are constants.
      // That is, they cannot be modified after they have been initialized.
      private static final double MPW = 10.0; // meters of go per watt
      private static final double SPW = 2.0; // seconds of charge per watt
      private static final double BCW = 1.0; // battery capacity, in watts
    }

    Mainly just constructing the robot is my problem because I tried some stuff but they kept coming back with an error or something.


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

    Default Re: Robot help.

    Hi!
    So, I've been working on it and I think I did somethings right...
    But now my question, main concern is:

    How do I get the robot to turn/move?

Similar Threads

  1. Replies: 8
    Last Post: April 21st, 2013, 08:20 AM
  2. How to Sendkeys to an application in Java using the Robot Class
    By JavaPF in forum Java SE API Tutorials
    Replies: 6
    Last Post: August 4th, 2011, 12:13 AM