This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin Cookbook and have Ken Kousen on-line!
See this thread for details.
Win a copy of Kotlin Cookbook this week in the Kotlin forum!
    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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Java method help

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Report post to moderator
So I rece ntly started an apprenticehsip and I am currently learning Java. I have been asked to write a public instance method moveBy() whose first argument is an int representing the distance to move and whose second argument is a char representing the direction in which to move. It should return no value.

Table 1: Directions and corresponding x and y increments

       direction xInc yInc
right  'R'        1 0
left 'L'       -1 0
up 'U'        0 -1
down'D'        0 1

 
Begin by declaring local int variables xInc and yInc and use the table above to set these for the appropriate increments depending on the supplied argument for direction.

      The method should then move the Shape (class) the required distance and direction 1 step at a time, using a loop.

I have only done the method so far.. the argumets are not correct!

 
Sheriff
Posts: 14622
243
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question multiple times. Locking this thread.

Please continue the conversation started here: https://coderanch.com/t/725048/java/Java-apprenticeship#3374027
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!