943,856 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 384
  • Java RSS
Apr 20th, 2009
0

Some proofreading and help

Expand Post »
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:
Java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sammo5889 is offline Offline
4 posts
since Apr 2009
Apr 20th, 2009
0

Re: Some proofreading and help

It compiles pretty well here, u should check if there is anything wrong with the rest of your code!
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
zyaday is offline Offline
70 posts
since Jun 2008
Apr 21st, 2009
0

Re: Some proofreading and help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sammo5889 is offline Offline
4 posts
since Apr 2009
Apr 21st, 2009
0

Re: Some proofreading and help

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Apr 22nd, 2009
0

Re: Some proofreading and help

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 ;
}
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
zyaday is offline Offline
70 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Bipartite Graph Algorithm
Next Thread in Java Forum Timeline: disallow more than one login





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC