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.