# Java custom class, need help!

• 10-09-2009, 08:04 PM
Keno777
Java custom class, need help!
I am a bit stuck right here.

Next, we will be implementing a method named scale. It will be a mutator method for the class that can be used to change the size of the Circle. The signature line is done for you.

* Inside the scale method write the Java statement(s) necessary to change the Circle's radius so that it is scaleFactor times its old value.

# Next, implement the method named setRadius that does not return a value and which has one parameter for the new radius of the Circle.

Here is the code. Radius and Scalefactor are at the bottom.

Code:

```public class Circle {         private double x;     private double y;     private double radius;         /**     * Default constructor for circles.     * The default circle is at (0,0) and radius of 1.     */     public Circle()     {         x = 0;         y = 0;         radius = 1;     }         /**     * constructs circles     *     * @param initialX The initial X of the center.     * @param initialY The initial Y of the center.     * @param initialRadius The initial radius.     */     public Circle(double initialX, double initialY, double initialRadius)     {         x = initialX;         y = initialY;         radius = initialRadius;     }             /**     * Accesses the X of the center point of the circle.     *     * @return the X of the center point     */     public double getX()     {         return x;     }         /**     * Accesses the Y of the center point of the circle.     *     * @return the Y of the center point     */     public double getY()     {         return y;     }         /**     * Accesses the radius of the circle.     *     * @return the radius     */     public double getRadius()     {         return radius;     }         /**     * Computes the diameter of the circle.     *     * @return the diameter     */     public double getDiameter()     {         return radius * 2;     }         /**     * Computes the area of the circle.     *     * @return the area     */     public double getArea()     {         return Math.PI * radius * radius;     }             /**     * Computes the circumference of the circle.     *     * @return the circumference     */     public double getCircumference()     {         double c = 2 * Math.PI * radius;         return c;     }         /**     * Changes the location of the circle.  The new     * location is <b>relative</b> to the old.     *     * @param deltaX The distance in the X dimension that the circle is moved.     *      More detailed explanation of deltaX.... blah blah blah.     * @param deltaY The distance in the Y dimension that the circle is moved.     */     public void translate(double deltaX, double deltaY)     {         x = x + deltaX;         y += deltaY; // y = y + deltaY;     }         /**     * Changes the location of the circle.  The new     * location replaces the old.     *     * @param newX The new X coordinate of the center.     * @param newY The new Y coordinate of the center.     */     public void setCenter(double newX, double newY)     {         x = newX;         y = newY;     }             public void scale(double scaleFactor)     {                       }         public void setRadius(double newRadius)     {             } }```
• 10-10-2009, 07:24 AM
CodesAway
What's the question or problem? We can't help you if you don't ask for something in specific.
• 10-10-2009, 04:06 PM
Keno777
Quote:

Originally Posted by CodesAway
What's the question or problem? We can't help you if you don't ask for something in specific.

Inside the scale method write the Java statement(s) necessary to change the Circle's radius so that it is scaleFactor times its old value.

# Next, implement the method named setRadius that does not return a value and which has one parameter for the new radius of the Circle.

This is what I need implemented in towards the bottom of the code in the body, I'm just not sure how.
• 10-10-2009, 04:20 PM
Fubarable
Quote:

Originally Posted by Keno777
Inside the scale method write the Java statement(s) necessary to change the Circle's radius so that it is scaleFactor times its old value.

Please try to attempt this yourself first, else you'll be cheating yourself.

You have the scaleFactor which is the parameter to the scale method, you have the radius value (which is held by the variable "radius"), and you want to use these two bits of information to change the radius. So inside the scale method create a single line of code that does this (or at least try your best attempt) and post it here. We can then help direct you if you are wrong.

Quote:

# Next, implement the method named setRadius that does not return a value and which has one parameter for the new radius of the Circle.

This is what I need implemented in towards the bottom of the code in the body, I'm just not sure how.
Again, it's a single line of code, and again you'll be far better served to first attempt a solution and post it here.

Much luck!

Edit: I added code tags to your original post to make the code more readable. Please look at my signature if you wish to do this yourself in future posts. Doing this will increase the chances that someone will be willing to read your code and to help you. Again, luck.
• 10-11-2009, 10:10 PM
Keno777
Quote:

Originally Posted by Fubarable
Please try to attempt this yourself first, else you'll be cheating yourself.

You have the scaleFactor which is the parameter to the scale method, you have the radius value (which is held by the variable "radius"), and you want to use these two bits of information to change the radius. So inside the scale method create a single line of code that does this (or at least try your best attempt) and post it here. We can then help direct you if you are wrong.

Again, it's a single line of code, and again you'll be far better served to first attempt a solution and post it here.

Much luck!

Edit: I added code tags to your original post to make the code more readable. Please look at my signature if you wish to do this yourself in future posts. Doing this will increase the chances that someone will be willing to read your code and to help you. Again, luck.

Only thing I have tried and thought of was something like this for the scalefactor.

x = scaleFactor * radius;
• 10-12-2009, 12:36 AM
Fubarable
Quote:

Originally Posted by Keno777
Only thing I have tried and thought of was something like this for the scalefactor.

x = scaleFactor * radius;

You may wish to re-read your instructions carefully as they will tell you exactly what to do:
Quote:

* Inside the scale method write the Java statement(s) necessary to change the Circle's radius so that it is scaleFactor times its old value.
So what do you need to change in the scale method? Is it x like you're showing us above? no. Again, the instructions are telling you all you need to know.
• 10-12-2009, 01:00 AM
Keno777
scaleFactor = radius * (something)

maybe this is correct? Trying to figure out what it means by "old value"
• 10-12-2009, 01:07 AM
Fubarable
Quote:

Originally Posted by Keno777
scaleFactor = radius * (something)

maybe this is correct? Trying to figure out what it means by "old value"

The left side of the expression is what you are trying to change, and the right side is how you are trying to change it. The instructions (again) are thus:
Quote:

* Inside the scale method write the Java statement(s) necessary to change the Circle's radius so that it is scaleFactor times its old value.
So what are we trying change here? That goes on the left. How are you supposed to change this? That goes on the right. It would be easy to just give you the answer, but I'm trying to make you think here. Please try again.
• 10-12-2009, 01:12 AM
Keno777
radius = scaleFactor *

Whats being changed is the Radius.(left) scaleFactor times old value is how to change it. (right) Still confused about what the old value would be after the times part.
• 10-12-2009, 01:18 AM
Fubarable
OK, you've got the left correct, and had the right side correct earlier, so now all you have to do is combine them:
Code:

`radius = scaleFactor * radius;`
A shorthand for this is to do it thusly:
Code:

`radius *= scaleFactor;`
for instance, if I do this:

Code:

```int i = 2; i = 4 * i;  // i now is 8 // another way to do this: // i *= 4; i *= 3;  // i now is 24 // another way to do this: // i = 3 * i;```
make sense?
• 10-12-2009, 01:31 AM
CodesAway
Code:

```int i = 2; i = 4 * i;  // i now is 8 // another way to do this: // i *= 4; i *= 3;  // i now is 24 // another way to do this: // i = 3 * i;```
Sorry for correcting such a small detail, but i *= 3 is another way to do i = i * 3. In multiplication, this doesn't matter, but in string concatenation, it makes a BIG difference.

For example,

Code:

```String string = "a"; string += "b"; // same as string = string + "b" // outputs "ab" System.out.println(string);```
As a note, these "shortened" assignment operators remove the left operand.

Again, sorry for correcting such a minor detail.
• 10-12-2009, 01:41 AM
Fubarable
Quote:

Originally Posted by CodesAway
Sorry for correcting such a small detail, but i *= 3 is another way to do i = i * 3. In multiplication, this doesn't matter, but in string concatenation, it makes a BIG difference.
//....
Again, sorry for correcting such a minor detail.

Good lord, never be sorry for correcting anything here, especially anything I post. I am grateful for all corrections as are most here. Many thanks.
• 10-12-2009, 03:27 AM
Keno777
Thanks for the help!