programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Simple math programming question

Ryan McClain
Ranch Hand
Posts: 153
1

The woman states: "A picture has a width of 185 pixels. You make the picture grow by 50 pixels on each side. Now you check the width again and you see it is now 285 pixels because it grew 50 pixels on each side.
If you were to grow the picture by 50%, it would have grown by 190 pixels."

I don't understand this. If a picture with an initial width of 185 pixels grows by 50%, then how could it possibly grow by 190 pixels? Wouldn't it grow by 185*0.5 (=92.5)?
185*1.5=277.5 is not 190.

I am puzzled. Could someone help me out here please?

John Morgan
Ranch Foreman
Posts: 78
1
It was a slip on her part, she was looking at the 285 when she mentioned it growing by 190 pixels, when in fact she should have said it would grow by approximately 90 pixels (as you pointed out 92.5 to be precise).

Ryan McClain
Ranch Hand
Posts: 153
1
Well, I hope you are right.

Jelle Klap
Bartender
Posts: 1952
7
I'm with John on this one, definitely a mistake.

Ryan McClain
Ranch Hand
Posts: 153
1
Perhaps she meant uniform scaling? 185+190=375. Then, 375/4 (each side)=93.75 //I don't think this is right though
So: 190 pixels growth in the x-axis is 50% bigger on a uniform scale.

If you observe the Method definition at 0:09, you will see it is defined as:

//Resizes this picture both horizontally and vertically.
//@param dw the amount by which to resize the width on each side
//@param dw the amount by which to resize the height on each side

Thus, she could have meant: grown by 190 pixels in total on the x-axis: 190/2=95 on each side, 51% growth in total.
This might make sense because she said "It grew by 100 pixels", in which case she was referring to the total growth, not the growth on one side. This is something to take into account.

The width is 185, but the height is something different.
Now, 185*1.5=277.5 What about the height? We don't know the height.

In any case, the method defines a growth in both the x-axis and the y-axis. So what height would it be if it were 50% bigger? We don't know that, or do we? Of course we could take a ruler to the screen, but I don't know about that.
Since the incorrect answer is: 50 pixels wider and 50 pixels taller, then that leads me to think the grow(dw,dw) method body multiplies its parameters by 2, stretching the picture out by x*2, meaning x on each side. Just a thought. I'm not a math wizard.

I have not had the time yet to think this through but I will later on.

Ulf Dittmer
Rancher
Posts: 42972
73
Note that there's also another possible interpretation of "if you were to grow the picture by 50%" - it could mean image size in terms of pixels. So sizeNew = xNew * yNew = 1.5 * sizeOld = 1.5 * xOld * yOld. I haven't seen the video, though, so I'm not sure if that makes sense in the context of her presentation.

Liutauras Vilda
Sheriff
Posts: 4917
334
I believe the final question is, what is the picture's size?

After increasing 50% grown up by 190 pixels

1) 185 pixels width
2) 185 - 50% is 92.5 pixels
3) 190 - 92.5 = 97.5 <-- the height grown by
4) 97.5 * 2 = 195 pixels <-- height of the picture

So the picture size is 185 x 195 pixels

Haven't seen this video, but i believe should be something like this.

Ryan McClain
Ranch Hand
Posts: 153
1
Liutauras Vilda wrote:I believe the final question is, what is the picture's size?

So the picture size is 185 x 195 pixels

Haven't seen this video, but i believe should be something like this.

Well, the picture does not have that kind of width/height ratio in the video. It's a nice solution you provided though.

 It is sorta covered in the JavaRanch Style Guide.