• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

I need method that will move rectangle

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EDIT2: I worked this out, for intrested i will update this for further usage.

Rectangle ia formed and moved by this test


There is 2 classes. First class is called point i am adding it here just for clarity as it should not be changed in any way


Second class is for rectangle itself it have constructor that forms rectangle and method that later moves it



Method should be used to move rectangle to position formed by test. But it return wrong values xpected: <110> but was: <10> Comparison Failure: Expected :110 Actual :10

 
Saloon Keeper
Posts: 7392
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Variables x & y are local and are being moved relative to anything.
 
Vlad Timoshuk
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:
Variables x & y are local and are being moved relative to anything.



TBH i think i made this method completly worng, i am a little bit stuck on this part for a long time,and not sure how it should look like.
 
Rancher
Posts: 218
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The names dx and dy implies that those variables should be the change in x and change in y, not the new x and y values. For example is x is 100, and dx is 10, then the new x value would be 110. How would you do this in code, what change do you need to make?

Also, you make int x and int y as local variables. This means that when the method ends, those x and y values will no longer exist - they are local to the method. Instead, you need to save it in a class level variable so you can use it later. What class-level variables store the x and y location of the rectangle?
 
Rancher
Posts: 180
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method doesn't do anything. Also, the variable "center" (line 4) is not used.
 
Saloon Keeper
Posts: 22658
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In strictly mathematical terms, "dx" and "dy" are offsets, not absolute co-ordinates. It would be more proper to say:
 
Let's go to the waterfront with this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic