Some proofreading and help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2009
Posts: 4
Reputation: sammo5889 is an unknown quantity at this point 
Solved Threads: 0
sammo5889 sammo5889 is offline Offline
Newbie Poster

Some proofreading and help

 
0
  #1
Apr 20th, 2009
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:
  1. public abstract class SpaceObject
  2. {
  3. //
  4. //ATTTRIBUTES
  5. //
  6.  
  7. private Space space;
  8.  
  9. private double x;
  10.  
  11. private double y;
  12.  
  13. private double radius;
  14.  
  15. private int hDirection;
  16.  
  17. private int vDirection;
  18.  
  19. private double hDelta;
  20.  
  21. private double vDelta;
  22.  
  23.  
  24. public SpaceObject( Space space, double x, double y, double radius)
  25. {
  26. }
  27.  
  28. public Space getSpace()
  29. {
  30. return space;
  31. }
  32.  
  33.  
  34. public double getX()
  35. {
  36. return x;
  37. }
  38.  
  39. public double getY()
  40. {
  41. return y;
  42. }
  43.  
  44. public double getRadius()
  45. {
  46. return radius;
  47. }
  48.  
  49. public double getHDelta()
  50. {
  51. return hDelta;
  52. }
  53.  
  54. public double getVDelta()
  55. {
  56. return vDelta;
  57. }
  58.  
  59. public int getHDirection()
  60. {
  61. return hDirection;
  62. }
  63.  
  64. public int getVDirection()
  65. {
  66. return vDirection;
  67. }
  68.  
  69. public void setHDelta(double x)
  70. {
  71. hDelta = x;
  72. }
  73.  
  74. public void setVDelta(double y)
  75. {
  76. vDelta = y;
  77. }
  78.  
  79. public void setHDirection(int x)
  80. {
  81. hDirection = x;
  82. }
  83.  
  84. public void setVDirection(int y)
  85. {
  86. vDirection = y;
  87. }
  88.  
  89.  
  90. public void move(double dx, double dy)
  91. {
  92. x = dx;
  93. y = dy;
  94. }
  95. }

all help is appreciated
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: zyaday is an unknown quantity at this point 
Solved Threads: 1
zyaday zyaday is offline Offline
Light Poster

Re: Some proofreading and help

 
0
  #2
Apr 20th, 2009
It compiles pretty well here, u should check if there is anything wrong with the rest of your code!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: sammo5889 is an unknown quantity at this point 
Solved Threads: 0
sammo5889 sammo5889 is offline Offline
Newbie Poster

Re: Some proofreading and help

 
0
  #3
Apr 21st, 2009
Sorry i left out the most important bit of the instructuctions, this follows on from what i had written:

Although your first task is not complete just yet, you may stop at this point and try to
compile and test your code. One way to test your code is to rightclick
on your
SpaceObject class and create a new instance. Since we don't have a space object at the
moment, we will use null as the first parameter. So, for example, you can try using these
parameter values: null, 100.0, 200.0, 10.0. A new SpaceObject will appear in the bottom
pane of the BlueJ window. Rightclick
on this object and inspect its attributes to see if
they contain the expected values. Also, test your move() method by rightclicking
on the
object and selecting move(dx,dy) with parameters 1.0 and 2.0. If you now inspect the
attributes of your object, the "x" attribute should now have value 101.0 and the "y"
attribute should now have value 202.0.

this is done in bluej. now when i do this, my values come out as 1.0 and 2.0 respectively for x and y.

but i have noticed when i right click the object to test move(), it is displayed as "void move(dx, dy)" not "move(dx, dy)" as is written in my outline.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,493
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 520
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Some proofreading and help

 
0
  #4
Apr 21st, 2009
You need to actually add 'dx' and 'dy' to the existing values of x and y. You have set them equal instead of adding.

Also, your constructor needs to set the values of your property variables equal to the parameter values that were passed. Your current constructor does not do anything as posted.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: zyaday is an unknown quantity at this point 
Solved Threads: 1
zyaday zyaday is offline Offline
Light Poster

Re: Some proofreading and help

 
0
  #5
Apr 22nd, 2009
I don't understand why it would display 101.1 and 202.0 because there is no line in the code that assigns the values of x and y . you should put in some assignment at the constructor class or a a setX and setY methods to set the values of x and y to the created object. Sth like this shold work

public SpaceObject( Space space, double x, double y, double radius)
{

this.x = x;
this.y = y ;
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC