Hi,
just doing a uni assignment and have completed a majority of it, just asking if someone could please proofread and help me out with the last line as i can't get it to compile.
heres my instructions:
All objects that float through space are instances of the SpaceObject class (or one of its
various subclasses). Your first task is to define some basic code for the SpaceObject
class. As you might expect, a space object has several attributes associated with it, a
constructor, and several methods. A description of each of these members is given
below, and you need to convert these descriptions into actual code. Your code must obey
the Golden Rule of OO (described at the end of your Tutorial 3 notes).
Attribute "space" of type Space.
Attribute "x" of type double.
Attribute "y" of type double.
Attribute "radius" of type double.
Attribute "hDirection" of type int.
Attribute "vDirection" of type int.
Attribute "hDelta" of type double.
Attribute "vDelta" of type double.
Constructor taking parameters for space, x, y, radius.
This constructor must initialise the 4 corresponding attributes from the 4 parameters.
Method getSpace which returns attribute "space".
Method getX which returns attribute "x".
Method getY which returns attribute "y".
Method getRadius which returns attribute "radius".
Method getHDelta which returns attribute "hDelta".
Method getVDelta which returns attribute "vDelta".
Method getHDirection which returns attribute "hDirection".
Method getVDirection which returns attribute "vDirection".
Method setHDelta which updates attribute "hDelta" from a parameter.
Method setVDelta which updates attribute "vDelta" from a parameter.
Method setHDirection which updates attribute "hDirection" from a parameter.
Method setVDirection which updates attribute "vDirection" from a parameter.
Method move taking parameters dx and dy (both of type double).
This method must update attributes "x" and "y" by adding dx to "x" and adding dy to "y".
i've been able to do everything except the method move.
here's what i've been able to do so far:
public abstract class SpaceObject
{
//
//ATTTRIBUTES
//
private Space space;
private double x;
private double y;
private double radius;
private int hDirection;
private int vDirection;
private double hDelta;
private double vDelta;
public SpaceObject( Space space, double x, double y, double radius)
{
}
public Space getSpace()
{
return space;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public double getRadius()
{
return radius;
}
public double getHDelta()
{
return hDelta;
}
public double getVDelta()
{
return vDelta;
}
public int getHDirection()
{
return hDirection;
}
public int getVDirection()
{
return vDirection;
}
public void setHDelta(double x)
{
hDelta = x;
}
public void setVDelta(double y)
{
vDelta = y;
}
public void setHDirection(int x)
{
hDirection = x;
}
public void setVDirection(int y)
{
vDirection = y;
}
public void move(double dx, double dy)
{
x = dx;
y = dy;
}
}
all help is appreciated