• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Classes and methods

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have posted this topic before ,but nobody helped me out. Please help me out...........
I am not sure how to go about . Can anyone please explain me how go with the convertYards() method.SO tht the value passed is converted to type Distances(newyard).

Q : Convert a feet variable of type Test. For example ,6002 feet is converted to 2feet,240 yards,1mile.

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you will want to add setters and getters to set and get the feet, yards and miles, because when you pass a Distances class, you will not be able to see those instance variables.

Mark
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: The getter and setter methods that Mark suggested are public methods that access private fields. For example...

(Search the forums for "encapsulation.")

You might also want a constructor that accepts these parameters. That is, Distance(int mi, int yd, int ft){...}.

Now, to be clear... Are you looking for a method that will take yards as input, and return (a reference to) a new instance of Distance that will have the input value expressed as miles, yards, and feet? For example, you call convertYards(1770L); and it returns a new Distance object in which miles = 1, yards = 3, and feet = 1?

If so, then this should get you started: The method will need to divide the long argument by YARDS_IN_MILE and truncate to get miles as an int. Then take the remainder of that division and...
 
reply
    Bookmark Topic Watch Topic
  • New Topic